Closed zhouzhongyuan closed 7 years ago
为什么引入Module的时候路径明明是Button/index.js,却可以用import Button from 'Button'? 这是ES6的特殊写法吗?
Button/index.js
import Button from 'Button'
答:
不是。这是模块加载器的工作,ES6没有规定任何和模块加载相关的规范。
这是Nodejs模块加载器所支持的写法,Webpack等为了兼容性也支持这种写法。
ES6 (EcmaScript 2015) modules: import index.js
javascript import from '/folder' with index.js
为什么引入Module的时候路径明明是
Button/index.js
,却可以用import Button from 'Button'
? 这是ES6的特殊写法吗?答:
不是。这是模块加载器的工作,ES6没有规定任何和模块加载相关的规范。
这是Nodejs模块加载器所支持的写法,Webpack等为了兼容性也支持这种写法。
参考
ES6 (EcmaScript 2015) modules: import index.js
javascript import from '/folder' with index.js