NPM package for react components without babel

I created a UI component using react / ES 6 and I need to reuse it for several other projects.

So, I thought this might be a nice little npm package.

Turns off the default for npm packages:

  • Place ES6 modules under /src

  • You have a separate /lib

    where the translated files live
  • Each release translates these modules to ES5

From my point of view, this is some (unnecessary?) Overhead. Projects that will use the package will also be written using ES6, so there is no need to translate the dependency.

Is there a way to bundle ES6 modules in an npm package and skip the upload process - and accept the fact that projects need to use ES6 to add this dependency?

Edit to clarify

@ D-reaper right, right. My problem is the importing side. I created a package containing Project.jsx

. When you try to import it, you receive the following error message:

ERROR in ./node_modules/foo/Project.jsx
Module parse failed: /../node_modules/foo/Project.jsx Unexpected token (14:11)
You may need an appropriate loader to handle this file type.

      

So my guess is that webpack / babel can't handle importing ES6 modules correctly, since they expect npm packages to include ES5 - is that a correct assumption? Can I get around this?

+4


source to share


2 answers


I will be using https://github.com/insin/nwb to put my reactive components in npm packages.



0


source


why don't you try Bit How to Share Your Components. You can use bitwise compilers or your own if you have a personal use case. You can read a little more https://codeburst.io/start-using-bit-to-build-react-apps-like-lego-7e14920f8de2



0


source







All Articles