我正在从API中获取一个angular模块的详细信息。模块在ES6中,我想将模块代码转换为ES5语法。
在安装了babel运行时之后,我尝试了import { transform } from 'babel-core';。但这是抛出错误。
load() {
fetch(url) // making the get request for loading the module response
.then(response => response.text())
.then(source => {
// i want to convert this response to es5 standard. right now it is in es6
});
}我的期望是在angular组件函数的运行时将es6转换为es5代码。
发布于 2019-07-19 21:27:50
执行以下操作:
npm install --save-dev @babel/core @babel/preset-env然后:
import * as babel from '@babel/core';
load() {
fetch(url)
.then(response => response.text())
.then((source) => {
return babel.transform(source, {
presets: ['@babel/preset-env']
});
});
}https://stackoverflow.com/questions/57111617
复制相似问题