1

Currently I am running a CLI command to transpile my node_modules:

babel --presets es2015 MYDIRECTORY --out-dir transpiled

That works fine, but with a problem. When I run it, it transpiles and copies files and folder structure. It only does it for *.js files. Other files (they dont need to get transpiled) are not copied.

So originaly I have this folder structure, before transpilation (plese see image):enter image description here

It does not copy other files. For one module it is ok, I cna manually copy those files. But for more complex structure it is very complex.

How can I tell Babel to do transpilaiton as it does, but also to copy other non *.js files as well.

Thank you

Amiga500
  • 5,874
  • 10
  • 64
  • 117

1 Answers1

1
  • Create a package.json if you don't have one yet.

    npm init // follow on screen instructions

  • Add a scripts key to the package.json with an array as value. Into the array add a command name as key and the commands to run as value.

Example package.json with the commands you need. To execute run: 'npm run compile'

I've added an exclude flag to the xcopy command. If you put the js extension in the exclude file, those files are excluded from copying. Remove the exclude flag to copy everything.

{
  "name": "someProject",
  "version": "0.0.1",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "copysrc": "XCOPY C:\\path\\to\\project\\src\\*.* C:\\path\\to\\project\\dist /S /I /Y /EXCLUDE:C:\\path\\to\\project\\xcopyexclude.txt",
    "babel": "babel --presets es2015 MYDIRECTORY --out-dir transpiled",
    "compile": "npm run copysrc && npm run babel"
  },
  "author": "someAuthor",
  "license": "ISC"
}

Links:

Community
  • 1
  • 1
blablabla
  • 1,468
  • 15
  • 17