Green
Green

Reputation: 30805

Babel doesn't ignore node_modules directory, although it is in "ignore" config

For some reason babel doesn't ignore node_modules directory, although I specified it in "ignore" field of .babelrc file. Why does it happen? How to make babel act as expected?

My goal is to compress and mangle all .js files in my ExpressJS app (particularly my all back end code) before I push my app to remote repo and then to server. So I use babel and babili.

Here is my .babelrc config:

{
    "presets": [
        ["latest", {
            "modules": false
        }]
    ],
    "env": {
        "development": {
            "presets": ["stage-0", "react", "babili"]
        },
        "production": {
            "presets": ["stage-0", "react", "babili"]
        }
    },
    "ignore": [
        "node_modules",
        "assets",
        "view",
        "public",
        "test",
        "spec",
        "logs",
        "lib/jasmine_examples",
        "db"
    ]
}

And I run babel from command line like this:

./node_modules/.bin/babel . -d ~/app_compressed/

And babel starts compressing node_modules directory:

node_modules\apache-crypt\gensrc\index.js -> C:\Users\user\app_compressed\node_modules\apache-crypt\gensrc\index.js
node_modules\apache-md5\gensrc\index.js -> C:\Users\user\app_compressed\node_modules\apache-md5\gensrc\index.js
node_modules\babel-preset-env\data\built-in-features.js -> C:\Users\user\app_compressed\node_modules\babel-preset-env\data\built-in-features.js
node_modules\babel-preset-env\data\plugin-features.js -> C:\Users\user\app_compressed\node_modules\babel-preset-env\data\plugin-features.js
node_modules\babel-preset-env\lib\default-includes.js -> C:\Users\user\app_compressed\node_modules\babel-preset-env\lib\default-includes.js
node_modules\babel-preset-env\lib\index.js -> C:\Users\user\app_compressed\node_modules\babel-preset-env\lib\index.js

Literally wrong behavior. How to fix it? How to make babel ignore folders specified in config?

Upvotes: 12

Views: 18330

Answers (3)

Green
Green

Reputation: 30805

Babel dev team say that there is a bug and ignored in config file doesn't work now.

However, I found that if you pass ignored directories in command line (with --ignored option), all works well, as expected. You can even pass globs in command line, like **/drafts

./node_modules/.bin/babel . -d ~/app_compressed/ --ignore node_modules,test,assets,stuff,views,public,test,spec,logs,lib/jasmine_examples,db,routes/api/drafts,**/drafts

Upvotes: 5

Amir Tahani
Amir Tahani

Reputation: 688

ignore get array of regexes so try like this

ignore: [
 /node_modules/,
 ...,
]

or you can pass a callback function like this

ignore: [
   /node_modules/,
   function(filepath) {
      return filepath !== "/path/to/es6-file.js";
   },
]

Upvotes: 7

s0up
s0up

Reputation: 422

I had the same problem after moving a Vue project from Cloud9 env to my PC and installing npm dependencies.

Solved this by:

  1. updating the Node.js with nvm for windows
  2. installing the Vue CLI globally and then running build in the Vue UI.

I am not sure what helped though.

Upvotes: 0

Related Questions