Internet Explorer 11,ECMAScript Object 属性分配问题

sha*_*_93 3 typescript ecmascript-6 webpack angular

在我的 Angular7 应用程序中,我进行了一些更改(angular7 升级和包依赖项升级等),我注意到我的应用程序无法在 PROD Internet Explorer 11 上正常运行。我在本地主机上工作时没有任何问题,但是在我将我的应用程序发布到 PROD 后,它给了我以下错误:

SCRIPT1003: Expected ':'
main-client.js (559,109)
Run Code Online (Sandbox Code Playgroud)

我调查了 main-client.js,我发现了这个:

Pr={"?defineBase":defineBase,
"?defineComponent":defineComponent,
"?defineDirective":H,
defineInjectable, ## This is line:559 and column:109 ##
Run Code Online (Sandbox Code Playgroud)

defineInjectable 需要是"defineInjectable": defineInjectable. 我已经使用以下示例在 IE11 开发人员工具中对此进行了测试,

c = 3; d=4; values = {a:1, b:2, c, d} output is: Expected ':'
Run Code Online (Sandbox Code Playgroud)

但这正是 IE11 想要的:

c = 3; d=4; values = {a:1, b:2, c:c, d:d} outpus is: OK
Run Code Online (Sandbox Code Playgroud)

PS:我正在使用 webpack 来构建应用程序。问题可能与 ECMAScript 版本有关,也可能与 Webpack 有关,但我无法指出。如果有人想要我的 webpack.config 文件,我也可以添加它。这是我的 tsconfig 文件:

配置文件

    {
  "compilerOptions": {
    "moduleResolution": "node",
    "module": "es2015",
    "target": "es5",
    "alwaysStrict": true,
    "noImplicitAny": false,
    "sourceMap": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "skipDefaultLibCheck": true,
    "skipLibCheck": true,
    "allowUnreachableCode": false,
    "lib": [
      "es2016",
      "dom"
    ],
    "types": [ "node" ]
  },
  "include": [
    "ClientApp"
  ]
}
Run Code Online (Sandbox Code Playgroud)

tsconfig.app.json

    {
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "module": "es2015",
    "baseUrl": "",
    "sourceMap": true,
    "types": ["node"]
  },
  "exclude": [
    "test.ts", 
    "**/*.spec.ts"
  ]
}
Run Code Online (Sandbox Code Playgroud)

tsconfig.spec.json

    {
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/spec",
    "module": "commonjs",
    "target": "es5",
    "baseUrl": "",
    "types": ["jasmine", "node"]
  },
  "files": ["polyfills.ts"],
  "include": ["**/*.spec.ts", "**/*.d.ts"]
}
Run Code Online (Sandbox Code Playgroud)

sha*_*_93 5

我已经通过编辑 webpack.config.js 和 webpack.config.vendor.js TerserPlugin(UglifyJsPlugin 的替代品)解决了这个问题,注意插件选项在两个文件(webpack.config.js 和 webpack.config.vendor.js 中重复) )。所有这些都需要进行编辑。

webpack.config.jswebpack.config.vendor.js 中

    new TerserPlugin({ //or UglifyJsPlugin
      cache: true,
      parallel: true,
      terserOptions: {
        compress: false,
        ecma: 6, //Setting this to "ecma: 5" solved problem.
        mangle: true,
        keep_classnames: true,
        keep_fnames: true
      },
      sourceMap: true
    })
Run Code Online (Sandbox Code Playgroud)

这就是我找到解决方案的地方,

我希望它会有所帮助。