2
const path = require("path");
module.exports = {
  mode: "production",
  entry: ["./index.js"],
  output: {
    path: path.join(__dirname, "dist"),
    filename: "bundle.js"
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/
      }
    ]
  }
};

I've tried different variation and configs :

  • target: "node"

  • exclude: [path.resolve(__dirname, "node_modules")]

  • exclude: ["/node_modules"]

Directory structure

Fabii
  • 3,820
  • 14
  • 51
  • 92
  • What are you trying to achieve? Are you ppreparing a library and don't want to have 3rd party libraries in your bundle? – lavor Sep 16 '19 at 11:46
  • Possible duplicate of [Webpack not excluding node\_modules](https://stackoverflow.com/questions/33001237/webpack-not-excluding-node-modules) – lavor Sep 16 '19 at 12:14
  • @lavor I usually use grunt, I'm new to webpack, so maybe I'm misunderstanding what webpack is actually bundling. When I look at my dist/bundle.js it looks like it is bundling in a ton of modules with my custom source files. – Fabii Sep 16 '19 at 18:05
  • If you are preparing final application, you need in bundle all dependencies that you are importing in your source files, so yes they will be there (you can optionally extract them in separate bundle with webpack application, but it is still necessary for runnig you app). But if you are preparing library that will be used in another applications, you need to specify 3rd party libraries as externals (e.g., see link in previous comment), hence your library will contain only your sources. – lavor Sep 16 '19 at 18:44

0 Answers0