3

This is, presumably, more a make than a webpack question.

I'm using good ol' make to manage dependencies and builds, and webpack for building JS components. Example:

Makefile:

foo.js: src/foo.js
    webpack -p

bar.js: src/bar.js
    webpack -p

webpack.config.js:

var webpack = require('webpack');

module.exports = {
    entry: {
      'foo': './src/foo.js',
      'bar': './src/bar.js',
    },
    output: {
        path: './',
        filename: '[name].js',
    }
};

Quite obviously, every time when any of src/{foo,bar}.js changes, Webpack runs and builds both files. This might not be fixable, as I've read that this is on purpose (to cater for possible interactions between the modules).

However, when both change, Webpack will run twice, because the recipes don't know of each other. This is unnecessary and gets out of hand quickly.

Is there any possibility to "collect" the files and make Webpack only run once, independently of how many source files changed?

Boldewyn
  • 81,211
  • 44
  • 156
  • 212

2 Answers2

0

You could specify the entry point from the command line:

foo.js: src/foo.js package.json
    webpack -p --entry src/foo.js

bar.js: src/bar.js package.json
    webpack -p --entry src/bar.js
Filip Dupanović
  • 32,650
  • 13
  • 84
  • 114
  • Thanks! I've tried that, too, actually, but to no avail. There might be differences between v1 and v2 of Webpack, but my v1 Webpack just adds the module from the command line to the first module listed in `entry`. – Boldewyn Jan 16 '17 at 19:43
0

This answer set me on the right track. GNU Make runs recipes of so-called pattern rules only once. So changing my Makefile to this does the trick of running Webpack exactly once:

foo.j% bar.j%:
    webpack -p

foo.js: src/foo.js
bar.js: src/bar.js
Community
  • 1
  • 1
Boldewyn
  • 81,211
  • 44
  • 156
  • 212