标签: es6-modules es6-module-loader
我曾经require,但我正在玩es6模块。我决定改变我的目录结构,这意味着我必须去改变所有的import语句(import thing from "../thing"变成import thing from "../../thing"等)。
require
import thing from "../thing"
import thing from "../../thing"
我不得不经历并改变了很多。使用node_modules,这绝不是问题。
您是否始终必须在es6模块中指定路径,或者是否有某种系统/操作顺序来查找模块?
答案 0 :(得分:1)
ES6中没有直接等效于node_modules的功能,这意味着没有模块可以按名称从预定义目录中导入。没有这样的目录,因此必须通过路径导入模块。
node_modules
ES6模块的做法是将它们放置在一个平坦的目录结构中,就像您使用所有../thing更改创建的目录结构一样。
../thing
顺便说一句,捆绑器将这一过程虚拟化了,这就是为什么您可能不习惯看到import '../thing'
import '../thing'
如果您想同时支持ES6和Node.js样式模块以及flat和node_modules目录结构,请查看此example及其介绍article。