vue打包上线之后 为什么会报webpackJsonp错误 JSONP不是跨域用的吗

我的PC端的vue项目打包上线之后 控制台报ReferenceError: webpackJsonp is not defined错误 之前都没这个问题 今天就现出了
不太明白JSONP不是跨域用的吗 我没有用到跨域 查了一下 说是用了CommonsChunkPlugin的问题 说是生成了公共文件但是没有在页面引入 看了关于也没有看明白是在哪个页面引入哪个公共文件
这是webpack.prod.conf.js文件的代码 我这是生成了哪个公共文件呀
new webpack.optimize.CommonsChunkPlugin({

  name: 'vendor',
  minChunks: function (module) {
    // any required modules inside node_modules are extracted to vendor
    return (
      module.resource &&
      /\.js$/.test(module.resource) &&
      module.resource.indexOf(
        path.join(__dirname, '../node_modules')
      ) === 0
    )
  }
}),
// extract webpack runtime and module manifest to its own file in order to
// prevent vendor hash from being updated whenever app bundle is updated
new webpack.optimize.CommonsChunkPlugin({
  name: 'manifest',
  minChunks: Infinity
}),
// This instance extracts shared chunks from code splitted chunks and bundles them
// in a separate chunk, similar to the vendor chunk
// see: https://webpack.js.org/plugins/commons-chunk-plugin/#extra-async-commons-chunk
new webpack.optimize.CommonsChunkPlugin({
  name: 'app',
  async: 'vendor-async',
  children: true,
  minChunks: 3
}),

这是打包之后的文件 应该不是在打包之后的index.html里引入吧 这里的代码都是压缩过的
图片描述

是在项目根目录下的index.html引入吗 是哪个公共文件呢
图片描述

阅读 8.2k
2 个回答
解决方法: 
在 build\webpack.prod.conf.js 中 HtmlWebpackPlugin 插件里添加以下代码改变文件加载顺序
chunks: ['manifest', 'vendor', 'app'],

例: 
new HtmlWebpackPlugin({
  filename: process.env.NODE_ENV === 'testing'
    ? 'index.html'
    : config.build.index,
  template: 'index.html',
  inject: true,
  minify: {
    removeComments: true,
    collapseWhitespace: true,
    removeAttributeQuotes: true
    // more options:
    // https://github.com/kangax/html-minifier#options-quick-reference
  },
  chunks: ['manifest', 'vendor', 'app'],              --->      新增
  // necessary to consistently work with multiple chunks via CommonsChunkPlugin
  chunksSortMode: 'dependency'
}),

试了没什么用啊

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题