Webpack-AngularJS应用程序无法在IE11上运行

时间:2018-09-07 10:44:03

标签: javascript angularjs internet-explorer webpack babel-loader

AngularJS应用程序正在使用webpack,创建了一些模块,这些模块也可以与webpack一起使用。在所有浏览器中运行该应用程序时,除IE11以外,其他所有功能均正常运行。这是IE11控制台中显示的当前错误。

SCRIPT1006: Expected ')'
File: vendor.bundle.js, Line 1, Column 546833

错误出现在一个已被“ webpackified”导入的模块上,尝试删除该模块以及另一个存在于不同repo错误中的组件。认为这可能是webpack错误,而babel可以解决问题。

.bablerc

{
"presets": [
    [ "env", {
     "targets": {
      "browsers": ["last 2 versions", "ie >= 11"]
    },
          "useBuiltIns": true
      }]
    ]
}

package.json

"devDependencies":{
  "babel-core": "^6.26.3",
  "babel-loader": "^7.1.4",
  "babel-polyfill": "^6.26.0",
  "babel-preset-env": "^1.7.0",
  "eslint": "^5.0.1",
  "eslint-loader": "^2.0.0",
  "file-loader": "^1.1.11",
  "happypack": "^5.0.0",
  "hard-source-webpack-plugin": "^0.9.0",
  "html-loader": "^0.5.5",
  "html-webpack-plugin": "^3.2.0",
  "json-loader": "^0.5.7"
},
"dependencies":{
  ...,
  "dataservice": "git+ssh://git@<remote-server>/dataService.get#webpackify",
  "cart": "git+ssh://git@<remote-server>/cart.git#webpackify"
},
"externals": [
  "dataservice/app",
  "cart/app"
]

使用angularJS版本“ ^ 1.7.2”和webpack版本“ ^ 4.12.1”

inside webpack.config.js具有在angularJS应用程序中构建外部模块以及当前javascript文件的功能。

webpack.config.js

module.exports = {
  entry: ["babel-polyfill", "./scripts/app.js"],
  modules.rules: [
    {  
      enforce: 'pre',
      test: /\.js$/,
      include: build_externals(),
      loader: 'eslint-loader'
    },
    {
      test: /\.js$/,
      include: build_externals(),
      use: 'happypack/loader?id=ECMAScript'
    }
  ],
  plugins: [
    {
     loader: 'babel-loader',
     options: {
      presets: ['env'],
      plugins: ['transform-es2015-modules-commonjs']
     }
   },
   new HappyPack({
    id: 'ECMAScript',
    threads: 4,
    loaders: happy_js_loader
   })
  ]
}

对这个问题失去了理智。希望那里的人能够为您提供帮助。预先感谢。

1 个答案:

答案 0 :(得分:0)

因此,解决我的问题的方法是为外部模块提供正确的路径。 Webpack将这些包括在构建过程中。 IE浏览器完美运行。

package.json

"externals": [
 "node_modules/dataservice/app",
 "node_modules/cart/app"
]