为了使用AggressiveSplittingPlugin并加速通过HTTP / 2下载捆绑包而转换到webpack2,我遇到了#34; Uncaught ReferenceError的问题:未定义webpackJsonp"初始化每个部分时。有没有人遇到这样的事情,你是否以某种方式解决了这个问题?
var path = require('path');
var webpack = require('webpack');
var ManifestPlugin = require('webpack-manifest-plugin');
module.exports = {
devtool: 'source-map',
entry: [
path.join(__dirname, '../../js/main'),
'jquery'
],
output: {
path: path.join(__dirname, '../../js/public'),
filename: '[name].js',
publicPath: '/assets/'
},
resolve: {
alias: {'jquery': path.join(__dirname, '../../js/modules/libs/jquery-2.2.3.min.js')},
extensions: ['.js', '.jsx'],
modules: [
path.resolve(path.join(__dirname, '../../js')),
"node_modules"
],
},
plugins: [
new webpack.optimize.OccurrenceOrderPlugin(true),
new webpack.NoEmitOnErrorsPlugin(),
new webpack.optimize.UglifyJsPlugin({
output: {
comments: false
},
compress: {
warnings: false,
// eslint-disable-next-line camelcase
screw_ie8: true
}
}),
new webpack.ProvidePlugin({
jQuery: 'jquery',
$: 'jquery',
jquery: 'jquery'
}),
new webpack.optimize.AggressiveSplittingPlugin({
minSize: 20000,
maxSize: 50000
}),
new ManifestPlugin({
fileName: 'manifest.json',
basePath: 'js/public/'
}),
],
module: {
rules: [
{
test: /\.js$/,
use: [
{
loader: 'babel-loader'
}
],
include: path.join(__dirname, '../../js'),
exclude: /node_modules/
}
]
}
};

答案 0 :(得分:-1)
您可以使用CommonsChunkPlugin来提取包含webpack运行时的清单:
new webpack.optimize.CommonsChunkPlugin({ name: 'manifest' })
您还必须确保此清单是第一个脚本,然后添加其他(积极拆分)块的脚本标记。