首頁  >  文章  >  web前端  >  webpack打包less或sass資源詳解

webpack打包less或sass資源詳解

WBOY
WBOY轉載
2022-08-09 14:20:161905瀏覽

本篇文章為大家帶來了關於javascript的相關知識,其中主要介紹了關於webpack打包less或sass資源的相關問題,包括了使用less-loader和sass-loader插件的相關內容,下面一起來看一下,希望對大家有幫助。

webpack打包less或sass資源詳解

【相關推薦:javascript影片教學web前端

##下載外掛


less 下載less套件和less-loader

sass 下載node-sass和sass-loader

使用外掛程式

webpack.config.js

 module: {                  //css打包规则
        rules: [{
            test: /\.css$/,        //把项目中所有以.css结尾的文件打包,插入到html里
            use: ["style-loader","css-loader"]  //css兼容loader,单独的css文件
        }, {
            test: /\.less$/,
            use: ["style-loader","css-loader","less-loader"]   //从右到左,内联样式
        },{
            test: /\.scss$/,
            use: ["style-loader","css-loader","sass-loader"]
        }]
    },
目錄結構

lessstyle.less

@width:200px;
@height:200px;
@color:red;

body {
  margin: 0;
  padding: 0;
}
p {
  color: @color;
  font-size: 25px;
}
h1 {
  color: blue;
  font-size: 88px;
}
.box2 {
  width: @width;
  height: @height;
  background-color: @color;
}
sassstyle.scss

$w:50px;
$h:100px;
.box3 {
  width: $w;
  height: $h * 3;
  background-color: greenyellow;
  color: bisque;
}
index.html

nbsp;html>


    
    Title


商城首页~~~~~~

打包css

    this is a box1
    this is a box2
    this is a box3
index.js

require("../css/style.css")
require("../css/lessstyle.less")
require("../css/sassstyle.scss")
console.log("首页专用js文件");
執行

webpack

html頁面

webpack打包less或sass資源詳解

#【相關推薦:

javascript影片教學 web前端

以上是webpack打包less或sass資源詳解的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:csdn.net。如有侵權,請聯絡admin@php.cn刪除