zhouzhongyuan / qa

Questions recods
MIT License
5 stars 1 forks source link

为什么引入Module的时候路径明明是`Button/index.js`,却可以用`import Button from 'Button'`? #20

Closed zhouzhongyuan closed 7 years ago

zhouzhongyuan commented 7 years ago

为什么引入Module的时候路径明明是Button/index.js,却可以用import Button from 'Button'? 这是ES6的特殊写法吗?

答:

不是。这是模块加载器的工作,ES6没有规定任何和模块加载相关的规范。

这是Nodejs模块加载器所支持的写法,Webpack等为了兼容性也支持这种写法。

参考