html5 - webpack打包js后,手机上报错:webpackJsonp is not defined
巴扎黑
巴扎黑 2017-04-17 14:27:14
0
3
961
在用MUI和Hbuilder做一个app时,开发中用webpack打包,刚开始没有用CommonsChunkPlugin提取common.js,今天用CommonsChunkPlugin提取出common.js之后,浏览器正常,但手机上测试就报错。
  • 浏览器没有问题,

  • 手机上运行报错: Uncaught ReferenceError: webpackJsonp is not defined

网上说是common.js没有加载,但是为什么浏览器和手机上测试会有区别,该如何解决?

  • 页面引入js如下:

        ...
        <script src="../dist/common.js"></script>
        <script src="../dist/attention.bundle.js"></script>
  • webpack.config.js

var webpack=require('webpack');
var vue=require('vue-loader');
var path = require('path');
var devServer=require("webpack-dev-server");


module.exports={
    //页面入口文件配置
    entry:{
        newsList:"./js/news/list_entry.js",//新闻
        newsPage:"./js/news/page_entry.js",//新闻详情页
        weather:"./js/weather/weather_entry.js",//天气
        monitor:"./js/monitor/monitor_entry.js",//监测
        attention:"./js/attention/att_entry.js"
    },
    output:{
        path:"dist",
        filename:"[name].bundle.js",
        publicPath: "/"
    },
    watch: true,
     resolve: {
          extensions: ['', '.js', '.vue'],
          alias: {
            components: path.join(__dirname, './src/components')
        }
      },
    plugins:[
        new webpack.optimize.CommonsChunkPlugin("common.js",["monitor","attention"])
    ],

    module:{        
        loaders:[
        {test:/\.css$/,loader:'style!css!'},
        {test:/\.scss/,loader:'style!css!sass'},
        {test: /\.(jpg|png)$/, loader: "url?limit=8192&name=../[path]/[name].[ext]"},

    
        ]
    }
}
巴扎黑
巴扎黑

répondre à tous(3)
Peter_Zhu

webpack配置文件中的 CommonsChunkPlugin 配置贴出来看看。应该是少了webpack的启动文件。

如果配置是大致下面的形式:

  ...
  new webpack.optimize.CommonsChunkPlugin(
        {names: ["common", "webpackAssets"]}
  ),
  ...

那么页面中还需要将‘webpackAssets’(名称不固定)文件引入到页面中,并且这个文件一定要放在其他js前引用!

迷茫

你先别管PC浏览器怎样,就用手机来调试,确定一下common.js到底加载了没有,然后再说下一步。

黄舟

你可以在你引入的每个js中第一行都弹出一句话来确定是不是所有js全部加载了

Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!