Home >Web Front-end >HTML Tutorial >webpack进阶之loader篇_html/css_WEB-ITnose
webpack的loaders是一大特色,也是很重要的一部分。这遍博客我将分类讲解一些常用的laoder
css-loader 处理css中路径引用等问题
style-loader 动态把样式写入css
sass-loader scss编译器
less-loader less编译器
postcss-loader scss再处理
npm install --save -dev css-loader style-loader sass-loader less-loader postcss-loader
栗子:
module: { loaders: [ {test: //.css$/, loader: "style!css?sourceMap!postcss"}, {test: //.less$/, loader: "style!css!less|postcss"}, {test: //.scss$/, loader: "style!css!sass|postcss"} ]}
babel-loader
jsx-loader
npm install --save-dev babel-core babel-preset-es2015 babel-loader jsx-loader
栗子
新建一个名字为 .babelrc 的文件
{ "presets": ["es2015","react"], "plugins":["antd"]}
新建一个名字为 webpack.config.js 文件
module.exports ={ entry: './entry.js', output: { path: __dirname, filename: 'bundle.js' }, module: {loaders: [ {test: //.js$/, loader: "babel", exclude: /node_modules/}, {test: //.jsx$/, loader: "jsx-loader"} {test: /.css$/, loader: 'style!css'} ] }};
url-loader
npm install --save-dev url-loadr
module: { loaders: [ {test: //.(jpg|png)$/, loader: "url?limit=8192"}, ]}
file-loader
npm install --save-dev file-loader
module: { loaders: [ { test: //.(png|jpg|jpeg|gif|svg|woff|woff2|ttf|eot)$/, loader: 'file' }, ]}
json-loader
npm install --save-dev json-loader
module: { loaders: [ {test: //.json$/,loader: 'json'}, ]}
raw-loader
npm install --save-dev raw-loader
module: { loaders: [ { test: //.html$/,loader: 'raw'}, ]}