I'm trying to include @mycompany/package1, and @mycompany/package2 to be compiled along with the rest of my code using babel-node
. Since package1 and package2 are in ES6. (Also note I'm not using Webpack)
In my jest
config I added the below option into my jest config which works fine. When testing the code will compile the packages correctly
"transformIgnorePatterns": [
"/node_modules/(?!(@mycompany)/).*/"
],
But when trying to run babel-node I get errors. In my babel.config.js
module.exports = {
presets: [
'@babel/preset-flow',
[
'@babel/preset-env',
{
targets: {
node: 8
}
}
]
],
plugins: ['@babel/plugin-proposal-class-properties']
};
I tried adding the below code to my babel.config.js but it still complains about ES6 errors within my node_modules/@mycompany/package1
I tried to include
the viz package but then babel wouldn't compile my src files
include: [path.resolve(__dirname, 'node_modules/@mycompany/package1')]
include: ['/node_modules/((@mycompany)/).*/']
I tried to exclude
everything but @mycompany packages but I still get transpile errors in my package1
exclude: [/node_modules\/(?!(@mycompany)\/).*/],
I tried playing with ignore but those don't seem like they are the right options based on reading the docs
I found out that we can do this with
webpack
to help bundle the packages with the rest of your code.This is my webpack file for NodeJS.
nodeExternal
tellswebpack
know not to bundle ANY node_modules.whitelist
is saying that we should bundle the packages we listedexternals: [ nodeExternals({ whitelist: [/@mycompany\/.*/] }) ]
This line means to exclude all node_modules EXCEPT @mycompany/* packages
exclude: /node_modules\/(?!(@mycompany)\/).*/,