Il mio webpack ha generato un grande file main.js (1.7mb) con un piccolo progetto di ~ 20-30 file inferiore a 100 righe ciascuno. Le dipendenze richieste sono pochi (Reagire, Fluxible) e sto usando tutti i plugin ottimizzare posso capire:Webpack per la creazione di file di grandi dimensioni con un piccolo progetto
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()
],
};
Che cosa sto facendo di sbagliato o dove posso migliorare ulteriormente le dimensioni del file?
Sì, sicuramente darei un'occhiata a questo e vedere come influenza il codice. Inoltre, ho trovato il mio errore che suggerirei di aggiungere alla risposta, stavo facendo 'devtools: true' che ha reso il mio file enorme mentre per la produzione non ha bisogno di essere vero. –
Fantastico, l'ho aggiunto. Ho dimenticato interamente 'devtool'. –
Uno strumento da riga di comando alternativo per l'analisi del bundle webpack: https://github.com/robertknight/webpack-bundle-size-analyzer – jmu