我是否需要在 tsloader 之上安装 babel-loader 才能使用 webpack 转译 typescript?
Do I need babel-loader on top of tsloader to transpile typescript with webpack?
我正在编写 webpack.config.js
以使用 tsloader
和 babel-loader
将打字稿(更准确地说是 tsx)转换为 ES5。
我有两个问题:
1) 即使 tsloader
输出 ES5 文件,我们还需要 babel-loader
吗?
2) 当目标为es5
时,将tsconfig.json
中的compilerOptions.module
设置为es6
是否有意义?
tsconfig.json
如下:
{
"compilerOptions": {
"module": "es6",
"target": "es5",
"jsx": "react"
}
}
提前致谢。
1) Do we still need babel-loader even though tsloader output ES5 files?
不,我们不这样做,除非需要使用 TypeScript 不支持的 non-compliant 功能(通常有 none)。
2) Does it make sense to set compilerOptions.module in tsconfig.json to es6 when the target is es5?
是的。它输出带有 ES 模块的 ES5 代码,可以被捆绑系统(Webpack 或 Rollup)处理。
我正在编写 webpack.config.js
以使用 tsloader
和 babel-loader
将打字稿(更准确地说是 tsx)转换为 ES5。
我有两个问题:
1) 即使 tsloader
输出 ES5 文件,我们还需要 babel-loader
吗?
2) 当目标为es5
时,将tsconfig.json
中的compilerOptions.module
设置为es6
是否有意义?
tsconfig.json
如下:
{
"compilerOptions": {
"module": "es6",
"target": "es5",
"jsx": "react"
}
}
提前致谢。
1) Do we still need babel-loader even though tsloader output ES5 files?
不,我们不这样做,除非需要使用 TypeScript 不支持的 non-compliant 功能(通常有 none)。
2) Does it make sense to set compilerOptions.module in tsconfig.json to es6 when the target is es5?
是的。它输出带有 ES 模块的 ES5 代码,可以被捆绑系统(Webpack 或 Rollup)处理。