I am trying to include my node_modules
so that Babel
transpiles them along with my src files.
The background of this is this: I have a monorepo
with multiple packages, but I do not want to setup a Webpack
/ Babel
thing for every single package. So my idea was to tell Webpack
/ Babel
in my main project to transpile its node_modules
that are imported by my sources.
I read for this I need to do this to tell Babel
to not ignore my node_modules
:
require('babel-register')({
ignore: false
});
Now this gives me errors because there are a lot of packages that are not mine and that don't play along with Babel
. But I can also tell Babel
to only include specific packages, which I do like this:
require('babel-register')({
only: /@elmc/
});
Because my packages are scoped under @elmc/package-name
. This solves the issue above but now my own package still won't get transpiled. I get an error saying:
.-collection-browser/CollectionBrowser.js Module parse failed: Unexpected token (23:13) You may need an appropriate loader to handle this file type.
| render() { | return <div>asd</div>; | }
He doesn't seem to transpile my JSX
and instead throws an error. I put my babel-register
call in my Webpack
config. I got my Webpack
config from create-react-app
so it is quite lengthy, but here it is in its entirety:
https://gist.github.com/LukasBombach/fe84a563ec9268dee32204d429763d5b