babel CLI copy nonjs files

yangli1990 picture yangli1990 · Sep 18, 2015 · Viewed 27.4k times · Source

I'm running a babel cli command

babel src --out-dir lib

To copy the es6 scripts from src into lib. However, it wont copy css/scss files I have in the src/ folder. Is there a way to make it copy them as well?

Answer

Emil Ingerslev picture Emil Ingerslev · Jan 27, 2016

Babel has the copy files option for this:

babel src --out-dir lib --copy-files

Note: It is true that babels primary purpose is to process javascript files, but babel's big suite of tools these day often makes it unnecessary to go for more complex build script setups as gulp and alike. A gulp-less setup could be adding this to packages.json:

{
  ...
  "devDependencies": {
    "babel": "*",
    "babel-cli": "^6.4.0",
    "babel-preset-es2015": "^6.3.13"
  },
  "scripts": {
    "watch": "babel --watch src --out-dir lib --source-maps inline --copy-files",
    "build": "babel src --out-dir lib --source-maps inline --copy-files" 
  },
  "babel": {
    "presets": [
      "es2015"
    ]
  }
}