babel不会将相对需求注入输出

时间:2017-05-10 08:08:28

标签: javascript ecmascript-6 requirejs babeljs

我对我的源文件运行babel,我想输出一个单独的文件,所有相关的导入都注入到文件中。

来源结构

src
│   index.js
│   relative-file.js    
│
└───some-folder
        another-relative-file.js

索引文件需要relative-filerelative-file需要another-relative-file

预期输出

index.js没有相对要求,所有内容都注入到这个文件中。

实际输出

内置index.js

require('./relative-file')

尝试过babel-cli命令

babel src --out-file distribution/index.js

输出一个dir会输出多个文件,就像源一样需要彼此。

babel src --out-dir distribution

1 个答案:

答案 0 :(得分:1)

我不认为babel有助于消除需求。您需要使用像webpack这样的捆绑器与babel结合使用来实现您的目标。