Search code examples
webpackwebpack-2

Webpack trying to bundle itself?


I have a fairly basic webpack config seen here.

module.exports = {
    entry: "./app/app.js",
    output: {
        filename: "public/bundle.js"
    },
    module: {
        loaders: [
            {
                exclude: /node_modules/,
                include: /app/,
                loader: 'babel-loader'
            }
        ]
    },
    // Without this the console says all errors are coming from just coming from bundle.js
    devtool: "eval-source-map"
};

However I'm trying to have webpack export jQuery as a global (since some of the packages I'm using look for a jQuery global).

The docs state here that you can do this:

new webpack.ProvidePlugin({
  $: 'jquery',
  jQuery: 'jquery'
})

However to add that block to my config I would have to include webpack in my above webpack.config.js. As when I add const webpack = require("webpack"); it seems webpack starts trying to bundle webpack. Which outputs a ton of errors to the console. Why is this happening, shouldn't webpack not be trying to bundle dependencies in webpack.config.js?

EDIT:

It appears webpack has always been bundling my config file, although it was never an issue until I included webpack in the file. The output shown below shows the config file being bundled with the above config.

Hash: cba679dd5938953cc8b8
Version: webpack 3.11.0
Time: 1576ms
           Asset     Size  Chunks                    Chunk Names
public/bundle.js  4.37 MB       0  [emitted]  [big]  main
   [1] ./app/modules/<filename>.js 1.77 kB {0} [built]
   [3] multi ./app/app.js ./webpack.config.js 40 bytes {0} [built]
   [4] ./app/app.js 174 bytes {0} [built]
   [5] ./app/js/<filename>.js 2.49 kB {0} [built]
   [6] ./app/js/<filename>.js 4.96 kB {0} [built]
  [13] ./webpack.config.js 664 bytes {0} [built]
    + 9 hidden modules

The line labeled [3] above is my issue, although my config doesn't appear to be telling webpack to do this at all.


Solution

  • The issue here was I was running webpack with the command npx webpack webpack.config.js. The correct command is just npx webpack, adding webpack.config.js adds that as another entry point.