Home  >  Q&A  >  body text

html5 - webpack打包js后,手机上报错:webpackJsonp is not defined

在用MUI和Hbuilder做一个app时,开发中用webpack打包,刚开始没有用CommonsChunkPlugin提取common.js,今天用CommonsChunkPlugin提取出common.js之后,浏览器正常,但手机上测试就报错。

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

        ...
        <script src="../dist/common.js"></script>
        <script src="../dist/attention.bundle.js"></script>
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]"},

    
        ]
    }
}
巴扎黑巴扎黑2765 days ago994

reply all(3)I'll reply

  • 天蓬老师

    天蓬老师2017-04-17 14:29:14

    Post the CommonsChunkPlugin configuration in the webpack configuration file and take a look. It should be that the webpack startup file is missing.

    If the configuration is roughly in the following form:

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

    Then the ‘webpackAssets’ (name is not fixed) file also needs to be introduced into the page, and this file must be referenced before other js!

    reply
    0
  • 迷茫

    迷茫2017-04-17 14:29:14

    Don’t worry about the PC browser for now, just use your mobile phone to debug it and make sure common.js is loaded before moving on to the next step.

    reply
    0
  • 黄舟

    黄舟2017-04-17 14:29:14

    You can pop up a sentence on the first line of each js you introduce to determine whether all js are loaded

    reply
    0
  • Cancelreply