webpack--css:scss文件的打包和分离(九)
目录结构
before
after
文件内容
index.html
<div id="biao"> <p>ss</p> </div>
src/css/index.scss
$biao-color:#fff; #biao{ $width:100px; width: $width; height: 100px; p{ color: $biao-color } }
entry.js
import css from './css/index.css'; import less from './css/index.less'; import sass from './css/index.scss'; document.getElementById('title').innerHTML = "hello11111";
webpack.config.js
安装依赖
因为sass-loader
要依赖node-sass
,所以要安装
cnpm install node-sass sass-loader --save-dev
index.scss文件打包到entry.js
{ test: /\.scss$/, use: [{ loader:'style-loader' },{ loader:'css-loader' },{ loader:'sass-loader' }] },
index.scss文件打包到index.css
{ test: /\.scss$/, use: ExtractTextPlugin.extract({ use: [{ loader: 'css-loader' }, { loader: 'sass-loader' }], fallback: 'style-loader' }) },
打包,运行
npm run build npm run server
相关推荐
前端 2020-08-03
maiktom 2020-05-11
StylusGalaxy 2020-04-29
前端 2020-04-29
骷髅狗 2020-04-24
jiangfulai 2020-04-18
jiangfulai 2020-04-11
jiangfulai 2020-03-05
taoqidejingling 2020-03-05
ZylCN 2020-03-03
前端 2020-02-19
不知道写什么 2020-01-16
xxuncle 2019-12-27
zhanghao 2019-12-27
wghou 2019-12-27
王军强 2019-11-17
ZylCN 2019-11-12
tianzyc 2019-11-08