11

In a nodejs express.js application, and trying to build the app using babel for cross browser compatibility.

package.json scripts:

"scripts": { "start": "node dist/app.js", "build": "babel src -d dist" } 

On running npm build and check my build folder everything builds correctly except my non-js files like [.html,.css,.ejs]. At the moment just copied those file to the build folder in their respective sub directories and everything works fine.

I have even tried "build": "babel src -d dist --ignore *.css,*.ejs,*.png,*.jpg"

Is there a way to do this in a better way instead of copying the non-js files. Thanks in advance any help will be highly appreciated.

9
  • i am not using web pack I just have .babelrc file Commented Sep 16, 2018 at 17:36
  • --ignore *.css,*.html,*.ejs should work. babeljs.io/docs/en/babel-cli#ignore-files Commented Sep 16, 2018 at 17:38
  • i have tried that before but when i check my dist directory the ignored files are not there.I have a css file somewhere in my src directory.It would be easier for me to have that same file in the dist folder once the build process is over Commented Sep 16, 2018 at 17:50
  • I have written an article about using Babel with Node.js/ Express.js linkedin.com/pulse/using-es6-babel-nodejs-harshal-yeole Commented Sep 16, 2018 at 17:57
  • 1
    The --copy-files flag doesn't take arguments. babeljs.io/docs/en/babel-cli#copy-files Commented Sep 16, 2018 at 18:05

1 Answer 1

24

If you have non-JavaScript files in the source directory that should be automatically copied to the output location when the command is run, simply add the --copy-files flag.

babel src -d dist --copy-files 

The flag doesn't take any arguments and will copy all non-JS files over.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.