babeljs - 巴别塔 --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
来将所有源代码编译src
到dist/
目录中。
但是,由于某些限制,我不能将 server.js 放在src
目录中。所以当我尝试babel . --out-dir dist/ --copy-files
在我的 package.json 中有一个脚本时,我让 babel 错误地将文件复制node_modules
到 中dist
,这不是我想要的。
所以我的问题是我如何只能从两者server.js
和src/
目标目录编译和复制文件dist/
而不复制文件node_modules/
?
$ cat babel.config.js
const presets = [
"@babel/preset-env",
];
module.exports = { presets };
解决方案
新的解决方案可用
--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
推荐阅读
- type-conversion - 将间隔列从 teradata 导入 SQL Server
- c++ - 我写了一个快速排序代码,逻辑看起来很正确,但控制台上没有输出
- android - 为 Native Android Project 构建 apk 时目标不兼容
- sql - 以下递归查询的最佳实现是什么?
- python - 如何在 Google Colaboratory 中使用 IBM python 模块“pixiedust”?
- gitlab - 如何正确沟通 CI/CD 管道中的不同阶段
- airflow - 我们如何将架构和表更改部署为 Airflow 工作流程的一部分?
- javascript - 如何仅使用围绕变量均值生成的钟形曲线对从 1 到 10 的钟形曲线上的数组中的对象进行评分,增量为 0.5
- excel - 有没有办法使用宏在两个不同的行之间切换
- bamboo - 在 Bamboo 服务器中发送构建开始通知