Dimitri Kopriwa
Dimitri Kopriwa

Reputation: 14365

Convert multiple es6 to multiple es5 file in order to create npm package

I have written some react components.

I have a folder of ES6 files with multiple files :

I wan't to import them like this in my futur project.

 import A from 'bootstrap-styled/components/A';

I would like to create a npm package.

I need to export them in ES5 format using the SAME directory structure.

I don't wan't a single output file.

Is there any existing program that can do that ?

Upvotes: 0

Views: 339

Answers (1)

Oleg Pro
Oleg Pro

Reputation: 2543

You need to have Babel installed in you project (I assume that it is already installed because without it you would not be able to run your ES6 in the browser. So I omit all the settings of Babel, just make sure that you have babel-cli in your project).

So all you need is:

babel components --out-dir dist

It will compile all your files from components to dist. Than you can publish it to NPM with

"main": "dist"

in your package.json

If you are looking for automatisation of this process try this boilerplate project - react-cdk. It'll do the exactly you asking: compile ES6 to ES5 every time you run npm publish

Upvotes: 2

Related Questions