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 關注
- 616 瀏覽
添加回答
舉報