Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allowlist doesn't seem to work #86

Open
wujekbogdan opened this issue Oct 5, 2020 · 3 comments
Open

allowlist doesn't seem to work #86

wujekbogdan opened this issue Oct 5, 2020 · 3 comments

Comments

@wujekbogdan
Copy link

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.

@liady
Copy link
Owner

liady commented Nov 17, 2020

@wujekbogdan which webpack-node-externals version do you have?

@liady liady closed this as completed Nov 17, 2020
@liady liady reopened this Nov 17, 2020
@wujekbogdan
Copy link
Author

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.

@liady
Copy link
Owner

liady commented Apr 21, 2021

@wujekbogdan is it working now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants