有一些webpack的问题。它构建正常,但当我打开我的网站时,我得到:Getting error: "Uncaught ReferenceError: webpackJsonp is not defined"
我认为我的CommonsChunkPlugin在我的应用程序捆绑之前正在运行?
知道我在src/config/webpack.config.js
建立dist/js/
的配置可能会有所帮助。
已阅读https://medium.com/@MarkEwersDev/note-to-self-if-you-ever-get-this-uncaught-referenceerror-webpackjsonp-is-not-defined-message-and-d354f5c4d335#.9cysuil5p和https://github.com/webpack/webpack/issues/368,但除非我遗漏了某些内容,否则似乎都没有帮助。
devtool: 'source-map',
entry: {
vendor: [
'react', 'react-dom', 'react-router', 'react-helmet', 'react-redux', 'moment-timezone', 'cookies-js', 'superagent', 'classnames', 'es6-promise'
],
app: [
'./src/client/entry',
'./scss/main.scss',
]
}
output:{
path: __dirname + '../../dist/js',
filename: 'app.js'
}
plugins:[
new webpack.optimize.CommonsChunkPlugin('vendor', 'vendor.js'),
new ExtractTextPlugin('../css/app.css', {
allChunks: true
}),
new webpack.DefinePlugin({
'process.env':{
'NODE_ENV': JSON.stringify('production')
}
}),
new webpack.optimize.AggressiveMergingPlugin(),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: true
},
output: {
comments: false
}
}),
...persistentPlugins
],
答案 0 :(得分:12)
webpackJsonp
函数由公共块定义,因此在编写vendor.js
标记时,必须始终先放置公共块(<script>
)。您也无法使用<script async>
。
另一种可能性是,当您将output.filename
设置为常量字符串时,您的供应商块会被条目块覆盖。请尝试将其命名为[name].js
,而不是app.js
。
答案 1 :(得分:0)
我在生产环境中面临同样的问题。我不知道为什么,但是当我上传使用生产webpack配置构建的捆绑包+供应商时,我得到了同样的错误。我刚刚解决了重启节点应用程序的错误。但我知道这不是一个好方法。
我在我的webpack生产配置中使用完全相同的插件,我很确定原因是其中一个webpack优化插件。
我的建议是: 尝试逐个评论这些优化插件( AggressiveMergingPlugin , DedupePlugin 和 UglifyJsPlugin ),您可能会发现哪一个导致问题。
我现在无法对其进行测试,因为它恰好发生在我的制作环境中,此时我无法停止/测试它。但是,如果它对你有用,请告诉我:)。