Should I include or exclude node_modules for various loaders in WebPack?
I've seen a number of configs that implicitly include it, and some that explicitly exclude it (either by excluding node_modules or only including the src or client folder) in various loaders (JS, TS, CSS, SCSS, file, url, raw, etc.)
I don't understand why you would or wouldn't include it. Obviously it brings in the code and includes it in the output build either way, I'm guessing it's just whether the loaders process it or not. I've only encountered one node module where it didn't work if the loader processed it, and so far none that didn't work one way or another otherwise.
Aside from one package, none of the others seem to care if they're included or excluded. What difference does it make to the output/browser?
For example:
'use strict';
const path = require('path');
module.exports = (root) => {
return {
// BABEL LOADER
// Reference: https://github.com/babel/babel-loader
// Transpile .js files using babel-loader
// Compiles ES6 and ES7 into ES5 code
// Run on .js files
test: /\.js$/,
// Use the babel-loader
use: [
// Babel transpiler, see .babelrc for configuration
{
loader: 'babel-loader',
options: {
sourceMap: true, // Emit sourcemaps
cacheDirectory: true // Cache compilation
}
}
],
// Aside from one package, none of the others seem to care if they're included or excluded.
include: [ path.resolve(root, 'client') ]
};
};