webpack-node-externals
webpack-node-externals copied to clipboard
allowlist doesn't seem to work
That's my current solution that works as exected. All node_modules are excluded from build except for some-library. When I compile the code then I can see the source of some-library being transpiled with Babel.
const path = require('path');
const pkg = require('./package.json');
const depsToBundle = ['some-library'];
const dependencies = Object.keys(pkg.dependencies).reduce((acc, name) => {
if (depsToBundle.includes(name)) {
return acc;
}
return {
...acc,
[name]: pkg.dependencies[name],
};
}, {});
module.exports = {
mode: 'production',
target: 'node',
entry: [path.join(__dirname, '/src/index.js')],
output: {
path: path.join(__dirname, '/dist'),
filename: 'index.js',
libraryTarget: 'commonjs',
},
module: {
rules: [
{
test: /\.js$/,
use: 'babel-loader',
exclude: new RegExp(`node_modules/(?!(${depsToBundle.join('|')})/).*`),
},
],
},
externals: [...Object.keys(dependencies)],
devtool: 'source-map',
};
I'd like to achieve the same with webpack-node-externals, so refactored my config to be:
const path = require('path');
const externals = require('webpack-node-externals');
const depsToBundle = ['some-library'];
module.exports = {
mode: 'production',
target: 'node',
entry: [path.join(__dirname, '/src/index.js')],
output: {
path: path.join(__dirname, '/dist'),
filename: 'index.js',
libraryTarget: 'commonjs',
},
module: {
rules: [
{
test: /\.js$/,
use: 'babel-loader',
exclude: new RegExp(`node_modules/(?!(${depsToBundle.join('|')})/).*`),
},
],
},
externals: [
externals({
allowlist: depsToBundle,
}),
],
devtool: 'source-map',
};
When I compile the code I can no longer see that lib being bundled.
I'm not sure is it a bug or am I missing something.
@wujekbogdan which webpack-node-externals version do you have?
I'm sorry but it was some work-in-progress code and I never committed it to my repo so I can't tell, but it was the most recent version of the lib because it was newly installed when reporting this bug.
@wujekbogdan is it working now?