我需要设置 webpack
来加载网络组件。麻烦的是我还想用typescript
。到目前为止,我找到的唯一解决方案是 web-components-loader .看起来它可以使用 babel
从 es6 转换代码。 typescript
是否有类似的可能性?
webComponentsLoader: {
transformJs: rawCode => {
return babel.transform(rawCode, {
presets: ['es2015']
}).code;
}
}
最佳答案
可以使用编译器提供的transpile
方法:
import * as ts from "typescript";
let compiledSource = ts.transpile("let x: string = 'string'", {
target: ts.ScriptTarget.ES2015
});
关于javascript - typescript 中有类似 'babel.transform().code'的功能吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46478887/