I need to have babel run on /node_modules/identicons/
However I still want to exclude all other packages.
Reason is the identicons package is using template strings and breaks when I run
"webpack -p"
String in question (node_modules/identicons/index.js):
str += `<rect x="${x}" y="${y}" width="${xside}" height="${xside}" style="fill:${color}" />`
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
//include: /node_modules/identicons/,
use: ["babel-loader"]
},
How would that pattern be written?
During your web pack build process ,need the node modules folder , because when you import a file from the node_modules , web pack will try to fetch the file from the particular node_module folder recursively.
Actually, those 'include' and 'exclude' properties are telling the loaders whether to include/exclude the files described (such as the contents of node_modules ), not webpack itself. So the 'excluded' modules you import from node_modules will be bundled - but they won't be transformed by babel.
Answer for Do I need Node_modules in production React? No, You don't need to push your node_modules folder to production whether it is a static export or dynamic build. When you export a static build the source file is converted into HTML & js files. So there is no need for node modules on production env.
I think you can use regex, something like
exclude: [
/node_modules\/(?!identicons).*/
]
Another way:
exclude: [
{
test: [
path.resolve(__dirname, './node_modules'),
],
exclude: [
path.resolve(__dirname, './node_modules/MODULE_TO_INCLUDE'),
path.resolve(__dirname, './node_modules/ANOTHER_MODULE_TO_INCLUDE'),
]
}
]
It worked for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With