Skip to content
This repository has been archived by the owner on Mar 22, 2023. It is now read-only.

Add support for Multi-compiler mode #13

Closed
PMCorbett opened this issue Feb 20, 2017 · 3 comments
Closed

Add support for Multi-compiler mode #13

PMCorbett opened this issue Feb 20, 2017 · 3 comments

Comments

@PMCorbett
Copy link
Contributor

I've ran into an issue using this plugin with multi compiler mode only outputting the last assets into the manifest. This is a problem that has been solved on the webpack-manifest-plugin, where they allow you to specify a cache object, which then adds to the manifest in every multi-compile.

I've had a go at getting copying their method into this plugin, which seems to work

var _ = require('lodash')
/**
 * Create a new StatsPlugin that causes webpack to generate a stats file as
 * part of the emitted assets.
 * @constructor
 * @param {String} output Path to output file.
 * @param {Object} options Options passed to the stats' `.toJson()`.
 */
function StatsPlugin (output, options, cache) {
  this.output = output
  this.options = options
  this.cache = cache || {}
}

StatsPlugin.prototype.apply = function apply (compiler) {
  var output = this.output
  var options = this.options
  var cache = this.cache

  compiler.plugin('emit', function onEmit (compilation, done) {
    var stats = compilation.getStats().toJson(options)
    cache = _.merge(cache, stats)
    var json = JSON.stringify(cache, null, 2)

    compilation.assets[output] = {
      size: function getSize () {
        return json && json.length || 0
      },
      source: function getSource () {
        return json
      }
    }

    done()
  })
}

module.exports = StatsPlugin

Is this something you'd be interested in incorporating into this plugin? And could I raise a PR to do so?

To give some context as why I want to do this; I am creating several themed bundles using themed-sass-loader within a webpack-rails app. Webpack-rails uses the manifest to load in the correct assets, and checks it for errors, etc., so an entry for each theme is needed.

@unindented
Copy link
Owner

Yes please! Open a PR with your changes, and a test if you can, and I'll merge it.

Thank you!

@rhys-vdw
Copy link

rhys-vdw commented Mar 1, 2017

Just for another use case here, I'm building a service worker and the application script using multi-compiler mode (also with webpack-rails).

@unindented
Copy link
Owner

If anybody opens a PR with the necessary changes and tests, I'll merge it!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants