5 回答

TA贡献1784条经验 获得超8个赞
webpack配置:
...
const ExtractTextPlugin = require('extract-text-webpack-plugin')
module.exports = {
...
output: {
path: path.join(__dirname, './dist'),
filename: 'js/[name].js',
publicPath: '/dist/'
},
module: {
loaders: [
...
{
test: /\.css$/,
loader: ExtractTextPlugin.extract({
fallbackLoader: 'style',
loader: 'css',
publicPath: '../'
})
},
]
},
plugins: [
...
new ExtractTextPlugin({
filename: 'css/[name].css',
disable: false,
allChunks: false
})
]
}

TA贡献1818条经验 获得超7个赞
开发环境和生产环境用的是同一个 webpack 配置文件,导致生产环境打包的 JS 文件包含了一大堆没必要的插件,比如HotModuleReplacementPlugin, NoErrorsPlugin 这时候不管用什么优化方式,都没多大效果。所以,如果你打包后的文件非常大的话,先检查下是不是包含了这些插件。

TA贡献1829条经验 获得超7个赞
webpack配置如下:
const ExtractTextPlugin = require('extract-text-webpack-plugin')
module.exports = {
output: {
path: path.join(__dirname, './dist'),
filename: 'js/[name].js',
publicPath: '/dist/'
},
module: {
loaders: [
{
test: /\.css$/,
loader: ExtractTextPlugin.extract({
fallbackLoader: 'style',
loader: 'css',
publicPath: '../'
})
},
]
},
plugins: [
new ExtractTextPlugin({
filename: 'css/[name].css',
disable: false,
allChunks: false
})
]
}
- 5 回答
- 0 关注
- 582 浏览
添加回答
举报