1

I have a library written in ES6/JSX and want to install it using npm install on a create-react-app application. How can I force babel to parse this lib from node_modules?

Something like not ignore node_modules/my-library when transpiling.

2
  • So you want to add a plugin/preset to Babel? Commented Jun 27, 2017 at 19:48
  • Right now I have this lib with a package.json file, some .jsx, some .css and some .png files and use it as a git submodule inside my application src path. I want to refer to this lib directly from node_modules so that I can import from "my-library", not from "../../my-library" and have it installed when someone types npm install without the pain of remembering the "--recursive" on git. Commented Jun 27, 2017 at 19:54

1 Answer 1

1

I think your library shouldn't rely on third applications dependencies,
then it won't be useful and it will only work on projects that contain Babel as a depency.

Instead, You should add Babel to your library dependencies, and create a build of your library using babel to transpile your ES6 code to ES5 code which will result in standard javascript.

Therefore, you can easily add it to any project by importing the build.

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

5 Comments

I already do this for a pure algorithm library. However, for this one, I need to include the assets (styles, images, fonts...) on the build. The babel src --out-dir dist command will only do the work for js files.
exactly, then that library shouldn't be a library, it should be part of your project instead since you need to different stuff during the build phase
but, can you show us that library? so we can see what is your library trying to do :)
I call it library because it will be a set of components that will be used by many applications with good version control. As you wish, here you can find a sample working fine as a git submodule.
@Wanderson take a look at this article, which explains in detail what you are trying to achieve. krasimirtsonev.com/blog/article/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.