blog icon indicating copy to clipboard operation
blog copied to clipboard

tsconfig 配置项 target/module/moduleResolution 区别

Open nmsn opened this issue 3 years ago • 1 comments

如题

nmsn avatar Dec 15 '22 14:12 nmsn

target

target 表示编辑结果的标准,作为某些特性的降级还是保留标准

Default: es3 Allowed: es3/es5/es6(es2015)/es2016...2022/esnext

相关属性 lib

选择 target 会自动引入相关lib 作为新特性的补充,也可手动配置

例如:

高级库:

  • es6(es2015): 增加了 array.find/Promise/Proxy/Symbol/Map/Set/Reflect 等
  • es7(es2016): 增加了 array.includes 等
  • es2017: 增加了 Object.entries/Object.values 等 ...
  • DOM: window/doucment 等
  • WebWorker: APIs available in WebWorker contexts
  • ScriptHost: APIs for the Windows Script Hosting System

还有额外的独立库

module

module 是指模块的处理方式

Default: CommonJS if target is ES3 or ES5,,ES6/ES2015 otherwise. Allowed: none/commonjs/amd/umd/system/es6(es2015)/es2020/es2022/esnext/node16/nodenext

  • commonjs/umd/amd 为我们熟悉的模块处理方式
  • system(不知道作用)
  • es2020 相对于 es6(es2015) 增加了动态 import 和 import.meta
  • node16/nodenext

moduleResolution

指定模块的解析策略, 与 module 是关联选项

https://www.typescriptlang.org/docs/handbook/module-resolution.html

nmsn avatar Dec 15 '22 16:12 nmsn