我有以下文件夹结构:
|-- public
|-- _category1
|-- foo.js
|-- bar.js
|-- _category2
|-- test.js
|-- _...
|-- src
|-- _category1
|-- foo.js
|-- bar.js
|-- _category2
|-- test.js
|-- _...
src文件夹中的文件是ES6,public文件夹中的必须是ES5。
有没有一种方法可以观察src文件夹及其子文件夹的更改(即保存的文件(,并将这些文件(而不是整个目录(转换为公用文件夹中相应的子文件夹?
我目前的解决方案是手动使用:
npx babel sourcefile --out-file targetfile
提前感谢
多亏了MTCoster的回答,我想出了一个愚蠢的简单答案
npx babel src --out-dir public --watch
您正在寻找--watch
选项:
要在每次更改文件时编译文件,请使用
--watch
或-w
选项:npx babel script.js --watch --out-file script-compiled.js
来自巴别塔文档