首页 > 解决方案 > 巴别塔 --copy-files 错误地复制 node_modules

问题描述

我的项目结构如下:

-rw-r--r--    1 chung2014  staff    2774 Nov  7 19:13 README.md
-rw-r--r--    1 chung2014  staff      75 Nov 26 23:27 babel.config.js
drwxr-xr-x  588 chung2014  staff   18816 Nov 26 23:01 node_modules
-rw-r--r--    1 chung2014  staff     781 Nov 26 22:25 nodemon.json
-rw-r--r--    1 chung2014  staff  377691 Nov 26 22:08 package-lock.json
-rw-r--r--    1 chung2014  staff    1551 Nov 26 23:27 package.json
-rw-r--r--    1 chung2014  staff    2941 Nov 26 23:29 server.js
drwxr-xr-x   11 chung2014  staff     352 Nov 26 23:03 src
drwxr-xr-x    5 chung2014  staff     160 Nov 26 21:55 test

如果我在src目录中有所有源代码(例如,也将 server.js 放入src其中),我可以在我的 package.json 中有一个脚本babel src --out-dir dist/ --copy-files来将所有源代码编译srcdist/目录中。

但是,由于某些限制,我不能将 server.js 放在src目录中。所以当我尝试babel . --out-dir dist/ --copy-files在我的 package.json 中有一个脚本时,我让 babel 错误地将文件复制node_modules到 中dist,这不是我想要的。

所以我的问题是我如何只能从两者server.jssrc/目标目录编译和复制文件dist/而不复制文件node_modules/

$ cat babel.config.js 

const presets = [
  "@babel/preset-env",
];

module.exports = { presets };

标签: babeljs

解决方案


新的解决方案可用

--no-copy-ignored是一个新参数,它允许--ignore在复制文件时尊重 的值。

用法

例子:

babel src -d dist --ignore 'src/**/*.spec.js' --copy-files --no-copy-ignored

规范文件不会出现在输出目录中。


来源:https ://github.com/babel/babel/issues/6226#issuecomment-590283042


推荐阅读