webpack打包的时候出现的错误,我看网上说是因为webpack4.0开始摒弃了CommonsChunkPlugin然后我跟着网上改了还是没用
来源:2-2 vue-loader配置
霍霍同学
2019-08-01

2回答
-
Jokcy
2019-08-01
这提醒已经很明显了啊。。。让改成config.optimization.splitChunks
022019-08-04 -
霍霍同学
提问者
2019-08-01
这是我的webpack.config.js
const path = require('path')
const VueLoaderPlugin = require('vue-loader/lib/plugin')
const HTMLPlugin = require('html-webpack-plugin')
const webpack = require('webpack')
const ExtractPlugin = require('extract-text-webpack-plugin')
const isDev = process.env.NODE_ENV === 'development'
const config = {
target: 'web',
entry: path.join(__dirname,'src/index.js'),
output:{
filename: 'bundle.[hash:8].js',
// filename: 'bundle.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()
],
}
if(isDev){
config.module.rules.push({
test: /\.styl/,
use: [
'style-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
},
hot: true
}
config.plugins.push(
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin()
)
}else{
config.entry = {
app: path.join(__dirname, 'src/index.js'),
vendor: ['vue']
},
config.output.filename = '[name].[chunkhash:8].js'
config.module.rules.push({
test: /\.styl/,
use: ExtractPlugin.extract({
use: [
'css-loader',
{
loader: "postcss-loader",
options: {
sourceMap: true,
}
},
'stylus-loader'
]
})
})
config.plugins.push(
new ExtractPlugin('styles.[chunkhash:8].css'),
)
}
module.exports = config
00
相似问题