Tôi đã tạo webpack của mình tạo tệp main.js lớn (1.7mb) với một dự án nhỏ ~ 20-30 tệp nhỏ hơn 100 dòng mỗi tệp. Các phụ thuộc yêu cầu rất ít trong số (Phản ứng, Fluxible) và tôi đang sử dụng tất cả các Plugin optimize tôi có thể hiểu:Webpack tạo tệp lớn với dự án nhỏ
module.exports = {
output: {
path: './build',
publicPath: '/public/',
filename: '[name].js'
},
debug: false,
devtool: 'eval',
target: 'web',
entry: [
'bootstrap-sass!./bootstrap-sass.config.js',
'./client.js',
],
stats: {
colors: true,
reasons: false
},
resolve: {
extensions: ['', '.js'],
alias: {
'styles': __dirname + '/src/styles',
'components': __dirname + '/src/scripts/components',
'actions': __dirname + '/src/scripts/actions',
'stores': __dirname + '/src/scripts/stores',
'constants': __dirname + '/src/scripts/constants',
'mixins': __dirname + '/src/scripts/mixins',
'configs': __dirname + '/src/scripts/configs',
'utils': __dirname + '/src/scripts/utils'
}
},
module: {
loaders: [
{ test: /\.css$/, loader: 'style!css' },
{ test: /\.js$/, exclude: /node_modules/, loader: require.resolve('babel-loader') },
{ test: /\.json$/, loader: 'json-loader'},
{ test: /\.(png|svg|jpg)$/, loader: 'url-loader?limit=8192' },
{ test: /\.(ttf|eot|svg|woff|woff(2))(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: "url?name=/[name].[ext]"},
{ test: /\.scss$/,
loader: ExtractTextPlugin.extract('style-loader',
'css!sass?outputStyle=expanded&' +
"includePaths[]=" +
(path.resolve(__dirname, "./node_modules"))
)
}
]
},
plugins: [
new webpack.NoErrorsPlugin(),
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
"windows.jQuery": "jquery"
}),
new ExtractTextPlugin("[name].css", {allChunks: true}),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin(),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.AggressiveMergingPlugin()
],
};
Tôi đang làm gì sai hoặc nơi tôi có thể nâng cao hơn nữa kích thước của tập tin?
Có chắc chắn tôi sẽ xem xét điều này và xem nó ảnh hưởng như thế nào đến mã. Ngoài ra, tôi thấy sai lầm của tôi mà tôi muốn đề nghị thêm vào câu trả lời, tôi đã làm 'devtools: true' khiến cho tệp của tôi rất lớn trong khi sản xuất không cần phải đúng. –
Tuyệt vời, tôi đã thêm điều đó. Quên về 'devtool' hoàn toàn. –
Một công cụ dòng lệnh thay thế cho phân tích gói webpack: https://github.com/robertknight/webpack-bundle-size-analyzer – jmu