webpack4--MiniCssExtractPlugin(extract-text-webpack-plugin)
在使用webpack打包时,将css代码从bundle.js中抽离出来,单独出一个模块,需要用到extract-text-webpack-plugin
插件
webpack版本不同,相对于的插件也不同,如下:
# for webpack 4 npm install --save-dev mini-css-extract-plugin # for webpack 3 npm install --save-dev extract-text-webpack-plugin # for webpack 2 npm install --save-dev # for webpack 1 npm install --save-dev
之前版本使用方法,可参照:https://github.com/webpack-contrib/extract-text-webpack-plugin
在webpack4
中,用mini-css-extract-plugin
替代。
webpack.config.js:
const MiniCssExtractPlugin = require(‘mini-css-extract-plugin‘); module.exports = { plugins: [new MiniCssExtractPlugin( filename:‘./css/[name].css‘ )], module: { rules: [ { test: /\.css$/i, use: [ { loader: MiniCssExtractPlugin.loader, options: { publicPath: ‘../‘, hmr: process.env.NODE_ENV === ‘development‘, }, }, ‘css-loader‘, ], }, ], }, };
更多mini-css-extract-plugin
的使用方法请查看:https://www.npmjs.com/package/mini-css-extract-plugin
相关推荐
waterv 2020-07-18
不知道该写啥QAQ 2020-11-12
webfullStack 2020-11-09
Yvettre 2020-09-15
想做大牛的蜗牛 2020-10-30
gloria0 2020-10-26
gaojie0 2020-09-11
SelinaChan 2020-08-14
不知道该写啥QAQ 2020-08-09
gloria0 2020-08-09
不知道该写啥QAQ 2020-08-02
hline 2020-07-29
SelinaChan 2020-07-28
wangdianyong 2020-07-23
webpackvuees 2020-07-23
yqoxygen 2020-07-20
不知道该写啥QAQ 2020-07-18
81463166 2020-07-17