javascript - Webpack 不会将 typescript 编译为 ES5?
问题描述
我正在尝试将我的代码编译为 ES5。我为此使用 typescript+webpack。然而,即使在遵循所有官方指南和各种教程之后,我仍然在我的 webpack 的最终 bundle.js 文件输出中获得箭头功能。
这是我的 webpack.config.js 文件
const path = require( 'path' );
module.exports = {
// generate source maps
devtool: 'source-map',
// bundling mode
mode: 'production',
// entry files
entry: './src/index.ts',
// output bundles (location)
output: {
path: path.resolve( __dirname, 'dist' ),
filename: 'bundle.js',
},
// file resolutions
resolve: {
extensions: [ '.ts', '.js' ],
},
// loaders
module: {
rules: [
{
test: /\.tsx?/,
use: {
loader: 'ts-loader',
options: {
transpileOnly: true,
}
},
exclude: /node_modules/,
}
]
},
// set watch mode to `true`
watch: true
};
这是我的 tsconfig.json 文件
{
"compilerOptions": {
"noImplicitAny": true,
"target": "ES5",
"module": "ES2015",
"sourceMap": true,
"importsNotUsedAsValues": "preserve"
}
}
这是我的 package.json 文件摘录:
"devDependencies": {
"ts-loader": "^8.0.12",
"typescript": "^4.1.3",
"webpack": "^5.11.0",
"webpack-cli": "^4.3.0"
},
解决方案
推荐阅读
- c++ - 尝试将 Ruby 自定义数组访问器转换为 C++ 下标运算符覆盖
- dart - Flutter 中的 ListView 中长按和滑动
- dart - 如何修复解决依赖关系...使用颤振运行时出错?
- python - 这个东西返回什么:frame[:, :, ::-1]
- java - Android - 尽管有内联权限和清单权限,但从存储“权限被拒绝”中读取文件
- mysql - 如何过滤掉具有匹配值的属性?
- python - 我可以在 TensorFlow 自定义层中添加 if...else 吗?
- c - memmove 是否为其临时数组使用动态内存
- c# - 如何在 C# 的递归函数或其他可用选项中使用 db.savechange() 函数提高实体框架中数据保存的性能?
- roblox - 需要围绕 x 轴旋转人形模型