使用 Babel 和 Vue.js 时 IE 11 出现脚本错误
SCRIPT errors with IE 11 when using Babel and Vue.js
我们的 Vue.js 应用程序在 Windows 10 / IE 11 上遇到问题。
应用程序一直在提供 SCRIPT1003: Expected ':'
,直到我们将 babel.config
更新为以下内容:
module.exports = {
presets: [
[
'@vue/cli-plugin-babel/preset',
{
targets: {
'ie': '11'
}
}
]
]
}
现在错误是 SCRIPT1002: Synxax Error chunk-vendors.js (11365, 9311)
,似乎与 vuelidate
节点模块有关。
看来我需要 exclude
上面的包,但我不明白语法应该放在哪里。
也可能会有多个包需要排除。
基础项目是使用 vue-cli 4.4.1
构建的,配置文件与库存安装相距不远
你想转译模块吗?您可以在 webpack.config.js
或 babel.config.js
中使用 exclude
属性 来转译模块。
您可以更改此行:
...
exclude: /node_modules/,
...
进入这个:
...
exclude: /node_modules\/(?!name-of-untranspiled-module)/,
...
如果您需要排除多个模块,您可以像这样扩展例外列表:
exclude: /node_modules\/(?![module1|module2])/
更多信息,您可以参考this link。
我们的 Vue.js 应用程序在 Windows 10 / IE 11 上遇到问题。
应用程序一直在提供 SCRIPT1003: Expected ':'
,直到我们将 babel.config
更新为以下内容:
module.exports = {
presets: [
[
'@vue/cli-plugin-babel/preset',
{
targets: {
'ie': '11'
}
}
]
]
}
现在错误是 SCRIPT1002: Synxax Error chunk-vendors.js (11365, 9311)
,似乎与 vuelidate
节点模块有关。
看来我需要 exclude
上面的包,但我不明白语法应该放在哪里。
也可能会有多个包需要排除。
基础项目是使用 vue-cli 4.4.1
构建的,配置文件与库存安装相距不远
你想转译模块吗?您可以在 webpack.config.js
或 babel.config.js
中使用 exclude
属性 来转译模块。
您可以更改此行:
...
exclude: /node_modules/,
...
进入这个:
...
exclude: /node_modules\/(?!name-of-untranspiled-module)/,
...
如果您需要排除多个模块,您可以像这样扩展例外列表:
exclude: /node_modules\/(?![module1|module2])/
更多信息,您可以参考this link。