我想为我的代码添加async-catch-loader
自动注入try catch
。我的项目基于 Vue CLI 和 TypeScript。所以我需要使用 webpack-chain 来改变ts
webpack 的规则,如下图所示:
{
test: /\.m?jsx?$/,
enforce: 'pre',
use: [
{
loader: '/Users/wjc/Documents/company/project/demos/async-test/node_modules/cache-loader/dist/cjs.js',
options: {
cacheDirectory: '/Users/wjc/Documents/company/project/demos/async-test/node_modules/.cache/ts-loader',
cacheIdentifier: '41bf2514'
}
},
{
loader: '/Users/wjc/Documents/company/project/demos/async-test/node_modules/babel-loader/lib/index.js'
},
{
loader: 'async-catch-loader',
options: {
catchCode: 'console.error(\'wujingchang\')'
}
}
{
loader: '/Users/wjc/Documents/company/project/demos/async-test/node_modules/ts-loader/index.js',
options: {
transpileOnly: true,
appendTsSuffixTo: [
'\\.vue$'
],
happyPackMode: false
}
},
]
},
但是,我不知道如何添加async-catch-loader
之前和之后的ts
规则。webpack-chain 有功能可以做到吗?babel-loader
ts-loader