webpack4.0 中使用extract-text-webpack-plugin報錯??Error: Path variable [contenthash] not implemented in this context: [name].[contenthash].css
Error: Path variable [contenthash] not implemented in this context: [name].[contenthash].css
Error: Path variable [contenthash] not implemented in this context: [name].[contenthash].css
2018-07-16
舉報
2018-07-18
可以參考這篇文章
https://blog.csdn.net/harsima/article/details/80819747
2020-03-03
在之前版本中我們使用
extract-text-webpack-plugin來提取CSS文件,不過在webpack 4.x中則應該使用mini-css-extract-plugin來提取CSS到單獨文件中基于webpack 3.0的Vue項目
const?ExtractTextPlugin?=?require('extract-text-webpack-plugin') config.module.rules.push( ????{ ????????test:/\.styl(us)?$/, ????????use:ExtractTextPlugin.extract({ ????????????fallback:'style-loader', ????????????use:[ ????????????????'css-loader', ????????????????{ ????????????????????loader:'postcss-loader', ????????????????????options:{ ????????????????????????sourceMap:true ????????????????????} ????????????????}, ???????????????'stylus-loader' ???????????????] ????????}) ????}) config.plugins.push( ????new?ExtractTextPlugin('styles.[hash:8].css') )基于webpack 4.0的Vue項目
const?MiniCssExtractPlugin?=?require('mini-css-extract-plugin') config.module.rules.push( ????{ ????test:/\.styl(us)?$/, ????use:[ ????????'style-loader', ????????MiniCssExtractPlugin.loader, ????????'css-loader', ????????{ ????????????loader:'postcss-loader', ????????????options:{sourceMap:true} ????????}, ????????'stylus-loader' ????????] ????} config.plugins.push( ????new?MiniCssExtractPlugin( ????????{ ????????????filename:?'styles.[contenthash:8].css' ????????} ????) )2018-11-12
我把contenthash改成了hash就編譯通過了
2018-07-18
util.js
刪掉 ExtractTextPlugin,改用 MiniCssExtractPlugin?
```
if (options.extract) {
let extractLoader = {
loader: MiniCssExtractPlugin.loader,
options: {}
}
return [extractLoader, 'css-loader'].concat(['postcss-loader'], loaders)
} else {
return ['vue-style-loader', 'css-loader'].concat(['postcss-loader'], loaders)
}
```