【发布时间】:2019-06-11 04:23:54
【问题描述】:
现在我一直在尝试转译一个使用对象扩展运算符的节点模块。这对我来说是个问题,因为我的应用程序假设支持 Edge 并且到目前为止,它不支持对象扩展运算符。
我通过将 useBabel 属性设置为 true 将 awesome-typescript 加载器配置为使用 babel,这样我就不需要自己安装 babel-loader。我还添加了一个名为 babel-preset-edge 的预设,它添加了许多有用的预设和插件。它默认添加的重要的一个是 @babel-plugin-proposal-object-rest-spread,它是转译该节点模块所必需的。
即使使用此设置,awesome-typescript 似乎总是忽略我要转换的模块。当我这样做时,这对我来说变得很明显
include: function(absPath) {
// I want to in include my source code or the module I want to transpile.
const includePath = /@furystack/.test(absPath) || /src/.test(absPath)
// this will always output true because all the paths have src in their path.
// Not a single one from node modules.
console.log(includePath)
return includePath
}
它应该输出一些真值和假值(它是我的源代码或 furystack 为真,其他任何东西为假)但事实并非如此。
这就是我的装载机的样子
module: {
rules: removeEmpty([
{
test: /\.(ts|tsx)$/,
use: [
{
options: {
useTranspileModule: true,
forceIsolatedModules: true,
useCache: true,
useBabel: true,
reportFiles: ['src/**/*.{ts,tsx}'],
babelCore: '@babel/core'
},
loader: 'awesome-typescript-loader'
}
],
include: function(absPath) {
return /@furystack/.test(absPath) || /src/.test(absPath)
}
},
}
这就是我的 .babelrc 的样子
{
"presets": [
[
"edge",
{
"transpile": "modern",
"modules": "false"
}
]
]
}
这就是我的 .tsconfig.json 的样子
{
"compilerOptions": {
"outDir": "lib",
"module": "esnext",
"target": "esnext",
"lib": ["es6", "dom"],
"sourceMap": true,
"jsx": "preserve",
"baseUrl": "./src",
"rootDir": "./src",
"moduleResolution": "node",
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"preserveConstEnums": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": false,
"alwaysStrict": false,
"allowSyntheticDefaultImports": true,
"noFallthroughCasesInSwitch": true,
"skipLibCheck": true,
"noEmit": true,
"types": ["jest", "node"]
},
"include": ["./src/**/*"],
"exclude": ["node_modules"]
}
我的配置有什么问题?
【问题讨论】:
标签: typescript babeljs awesome-typescript-loader