liady / webpack-node-externals

Easily exclude node modules in Webpack
MIT License
1.3k stars 62 forks source link

Undesired package being included in the bundled ouput #113

Closed pikonha closed 3 years ago

pikonha commented 3 years ago

Hi there,

I have a monorepo that depends on an external npm package called @elastic/synthetics. This package cannot be bundled by webpack because it have many files that are not handled by default (e.g .exe, .apk...) and for my purposes it can be download directly from NPM with no problem.

So in order to create a bundle file from some of the internal packages, I'm using this webpack-node-externals tool. The problem is that even with the configuration, webpack is trying to include the package in the bundled output. Here are my config files:

package.json

{
  "name": "@rd-synthetics/accounts-auth",
  "version": "1.0.0",
  "license": "MIT",
  "scripts": {
    "build:webpack": "NODE_PRESERVE_SYMLINKS=1 webpack --config webpack.js"
  },
  "dependencies": {
    "@elastic/synthetics": "^1.0.0-beta.10",
    "@rd-synthetics/environment": "*",
    "@rd-synthetics/models": "*"
  },
  "devDependencies": {
    "webpack": "^5.48.0",
    "webpack-cli": "^4.7.2",
    "webpack-node-externals": "^3.0.0"
  }
}

webpack.js

const nodeExternals = require("webpack-node-externals")

module.exports = {
  externalsPresets: { node: true },
  mode: "development",
  entry: "./src/signin.journey.js",
  output: {
    filename: "index.js"
  },
  externals: [nodeExternals({
    allowlist: /@rd-synthetics/
  })]
}