還是關(guān)于 extract-text-webpack-plugin 插件的問題....
在網(wǎng)上找到一位仁兄的代碼,鏈接 https://segmentfault.com/a/1190000013994415,
然后就根據(jù)他的來試了一下,
------ webpack.config.js ------
const?path?=?require('path') const?HTMLPlugin?=?require('html-webpack-plugin') const?webpack?=?require('webpack') const?MiniCssExtractPlugin?=?require('mini-css-extract-plugin') const?{ VueLoaderPlugin }?=?require('vue-loader'); const?isDev?=?process.env.NODE_ENV?===?'development' const?config?=?{ target:?'web', entry:?path.join(__dirname,?'src/index.js'), output:?{ filename:?'bundle.[hash:8].js', path:?path.join(__dirname,?'dist') }, module:?{ rules:?[ { test:?/\.vue$/, loader:?'vue-loader' }, { test:?/\.jsx$/, loader:?'babel-loader' }, { test:/\.(gif|jpg|jpeg|png|svg)$/, use:?[ { loader:?'url-loader', options:?{ limit:?1024, name:?'[name]-aaa.[ext]' } } ] } ] }, plugins:?[ new?VueLoaderPlugin(), new?webpack.DefinePlugin({ 'process.env':?{ NODE_ENV:?isDev???'"development"'?:?'"production"' } }), new?HTMLPlugin(), new?MiniCssExtractPlugin({ //?Options?similar?to?the?same?options?in?webpackOptions.output //?both?options?are?optional filename:?"[name].css", chunkFilename:?"[id].css" }) ] } if(isDev){ config.module.rules.push({ test:?/\.styl/, use:?[ MiniCssExtractPlugin.loader, 'css-loader', { loader:?'postcss-loader', options:?{ sourceMap:?true } }, 'stylus-loader' ] }) config.devtool?=?'#cheap-module-eval-source-map' config.devServer?=?{ port:?8000, host:?'0.0.0.0', overlay:?{ errors:?true }, //?open:?true //?historyFallback:?{ //?} hot:?true } config.plugins.push( new?webpack.HotModuleReplacementPlugin(), new?webpack.NoEmitOnErrorsPlugin() ) }?else?{ config.output.filename?=?'js/[name].[chunkhash:8].js'; config.module.rules.push( { test:?/\.styl$/, use:?[ MiniCssExtractPlugin.loader, 'css-loader', { loader:?'postcss-loader', options:?{ sourceMap:?true } }, 'stylus-loader' ] } ) config.plugins.push( new?MiniCssExtractPlugin({ filename:?"[name].[chunkhash:8].css", chunkFilename:?"[id].css" }) ) } module.exports?=?config;
然后,的確是有生成(然而我已經(jīng)搞不懂到底會生成什么樣子的文件了......),生成的dist如下
,
然而,也有報錯....,真的看不懂了.....,如下圖
求個大佬來說說到底是怎么回事.....改成 mini-css-extract-plugin 到底是怎么個用法....
求你們了...
2019-01-21
} else {
// 修改打包的js名稱
config.output.filename = '[name].[hash:8].js'
// 添加正式環(huán)境的規(guī)則
config.module.rules.push({
test: /\.styl$/,
use: extracttextwebpackplugin.extract({
fallback: 'style-loader',
use: [
'css-loader',
{
loader: 'postcss-loader',
options: {
sourceMap: true
}
},
'stylus-loader',
]
})
})
config.plugins.push(
new extracttextwebpackplugin('styles.[Hash:8].css')
)
}
2018-09-05
樓上的是webpack4.+常規(guī)用法。
但你還可以嘗試使用:
npm install --save-dev extract-text-webpack-plugin@next
升級extract-text-webpack-plugin為4.0best版本
然后將
contentHsah:8 更改為 chunkhash:8
這樣打包出來的和老師的是一樣的
2018-08-05
我的也是基于webpack4.0+ 的,這個里有一篇文章
https://blog.csdn.net/harsima/article/details/80819747
介紹很清楚,不過里面的寫法和老師的不太一樣,不懂的可以看我的GitHub??https://github.com/marin1993/todo? 里面用的是?mini-css-extract-plugin