Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

babel . --copy-files incorrectly copy node_modules

Tags:

babeljs

I have a project structure like the following:

-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

if I have all the source code inside the src directory, (e.g put server.js into src as well), I can have a script babel src --out-dir dist/ --copy-files in my package.json to compile the all the source code in src to dist/ directory.

However, due to some restriction, I cannot put my server.js inside src directory. So when I try to have a script babel . --out-dir dist/ --copy-files in my package.json, I let babel incorrectly copy files in node_modules to dist, which is not what I want.

So my question is how I can just only compile and copy files from both server.js and src/ to the destination directory dist/ without copying files in node_modules/?

$ cat babel.config.js 

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

module.exports = { presets };
like image 974
bufferoverflow76 Avatar asked Sep 17 '25 02:09

bufferoverflow76


1 Answers

New solution available

--no-copy-ignored is a new argument which allows the value of --ignore to be respected when copying files.

Usage

Example:

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

The spec files are not going to be present on the output directory.


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

like image 188
Lucio Avatar answered Sep 19 '25 14:09

Lucio