在巴贝尔7上解构进口是否有可能?
使用babel 7,您无法真正导出模块并使用babel语法解构它们。是否有插件,旧语法或我遗漏的东西允许我执行以下操作?
// file1.js
export const x = 0;
export const y = 1;
export default z;
// file2.js
import { x, y } from './file1.js'
console.log(x); // output: 0
console.log(y); // output: 1
回答如下:
好的,我设法解决了Felix的问题。我的误解非常愚蠢:export
仍会声明你之后定义的任何变量,例如:
const x = 0;
export const x = 0; // this will be invalid, because x is a constant already
我一直在我的webpack上遇到语法错误,并且不明白这是因为我两次声明变量,所以我认为这是webpack或babel的问题。