最近在看skywalking-client-js(使用ts编写的项目),发现其项目打包后代码没做IE11兼容处理,比如代码中存在箭头函数、const声明,请问该如何配置才能将箭头函数、const变量等转换?。在项目中tsconfig.json,代码如下:
{
"compilerOptions": {
"declaration": true,
"outDir": "./lib/",
"noImplicitAny": true,
"sourceMap": true,
"module": "es6",
"target": "es5",
"allowJs": true,
"allowSyntheticDefaultImports": true,
"moduleResolution": "node"
}
}
尝试安装配置了babel-loader,可能方式不太对,没起到效果。
原相关webpack配置如下:
const config = {
entry: './src/index.ts',
devtool: 'inline-source-map',
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: 'ts-loader'
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
mainFiles: ['index'],
},
output: {
filename: 'index.js',
path: path.resolve(__dirname, 'lib'),
publicPath: '/',
},
plugins: [
new WebpackConcatPlugin({
bundles: [
{
dest: './lib/src/types.d.ts',
src: './src/**/*.d.ts',
},
],
}),
],
devServer: {
contentBase: './lib',
hot: true,
},
optimization: {
moduleIds: 'named',
},
};
最终问题改法如下: