Maison  >  Questions et réponses  >  le corps du texte

javascript - webpack设置chunks后提示 webpackJsonp is not defined,如何解决?

1.由于是两个页面就设置了两个入口,那么现在就有一个问题,就是打包的时候两个页面引入的所有js文件都会打包进去。
2.为了解决这个问题,看了下网上的说明可以使用chunks指定引入的打包文件,结果指定以后报错了。


webpack.config.js

entry:{
      index: './src/index.ts',
      home: './src/home.ts'
  },

webpack.prod.conf.js

 plugins: [
    new HtmlWebpackPlugin({         
      filename: config.build.index,
      template: 'index.html',
      inject: true,
      //chunks这个参数告诉插件要引用entry里面的哪几个入口
      chunks:['index'],      //这里设置以后报错,提示 webpackJsonp is not 
      minify: {
        removeComments: true,
        collapseWhitespace: true,
        removeAttributeQuotes: true

    
      },
     
      chunksSortMode: 'dependency'
        }),
      new HtmlWebpackPlugin({          //另外一个入口文件
      filename: config.build.home,
      template: 'home.html',
      inject: true,
      //chunks这个参数告诉插件要引用entry里面的哪几个入口
      chunks:["home"],         //这里设置以后报错,提示 webpackJsonp is not defined                      
      minify: {
        removeComments: true,
        collapseWhitespace: true,
        removeAttributeQuotes: true
       
      },
    CommonsChunkPlugin
      chunksSortMode: 'dependency'
       
    }),

不知道是缺少其他配置还是什么原因,谢谢大家的解答,感激不尽

天蓬老师天蓬老师2723 Il y a quelques jours369

répondre à tous(1)je répondrai

  • 迷茫

    迷茫2017-04-11 10:36:17

    你的commonChunk也要放进chunks里面的

    répondre
    0
  • Annulerrépondre