3
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

4
  • What are you trying to achieve? Are you ppreparing a library and don't want to have 3rd party libraries in your bundle? Commented Sep 16, 2019 at 11:46
  • Possible duplicate of Webpack not excluding node_modules Commented Sep 16, 2019 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. Commented Sep 16, 2019 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. Commented Sep 16, 2019 at 18:44

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.