3

在使用 Vue 2 和 Vue CLI 时,这个问题在几个方面让我感到困惑,现在又开始了一个新的 Vue 3.0 beta 项目。

Even with the currently newest Vue CLI version 4.3.1, when choosing TypeScript option, the boilerplate code you are given has compilerOptions target set as esnext in tsconfig.json.

虽然Vue 2 TypeScript 指南正在指导:

# Recommended Configuration
// tsconfig.json
{
  "compilerOptions": {
    // this aligns with Vue's browser support
    "target": "es5",
    // this enables stricter inference for data properties on `this`
    "strict": true,
    // if using webpack 2+ or rollup, to leverage tree shaking:
    "module": "es2015",
    "moduleResolution": "node"
  }
}

目前Vue Next repo 正在使用esnext,虽然此时 IE11 支持尚未准备好(但无论如何可能不会影响此配置)...

使用 Vue 3 时,此编译器目标的推荐设置是什么?

我需要支持低至 IE11 的旧版浏览器,但这个特定的应用程序项目在其初始发布之前有足够的时间等待 Vue 3 的完整发布。

4

1 回答 1

4

正如Vue 3 存储库所述,

当前的实现需要在运行时环境中使用本机 ES2015+,并且不支持 IE11(目前)。IE11 兼容版本将在我们达到 RC 阶段后进行。

如前所述,Vue 3 的目标是当前esnext,它依赖于现代 JS 功能,目前针对的是常青浏览器的开发,不应该在生产中使用。即使目标较低,Vue 3 也无法在旧版浏览器中使用,因为它目前依赖于无法填充的 ES6 特性的代理。

使用现有 Vue 3 构建的项目不会受益于target低于es2018可能是最不常见的分母,对象传播是 Vue 3 代码库中使用的最流行的最新添加之一,并且不能被 polyfill。TypeScript 目标可以实验性地降低到启用选项以早期检测某些兼容性问题es5downlevelIteration

预计将为旧版(IE11)和现代浏览器维护单独的 Vue 3 版本。不同之处在于如何处理响应性,因为Proxy允许高级更改检测但不能在旧版浏览器中实现。该项目应遵循Vue 2 反应性的现有指南,以便与旧版 Vue 3 构建兼容。

于 2020-05-07T14:37:18.543 回答