mipearson / webpack-rails

Integrate webpack with your Ruby on Rails application
MIT License
544 stars 82 forks source link

Multi-compiler mode #19

Open RyanS opened 8 years ago

RyanS commented 8 years ago

This may very well be an issue with webpack and not webpack rails but when using multi compiler mode (https://github.com/webpack/webpack/tree/master/examples/multi-compiler) the manifest that rails reads gets overwritten by each "compile target" so only one package is available in the manifest.

Any way to have both in the manifest? There seems to be a mention of it here: https://www.npmjs.com/package/webpack-manifest-plugin but I have no idea what "pass a shared {} to cache option" really means

RyanS commented 8 years ago

Aright so it seems that the deal is with the stats-webpack-plugin that the gem relies on to create the manifest file. It has no way to merge both compiles from a multi compile setup. I guess a solution would be allow the gem to read from multiple manifest files and merge them internally.

Unless I am missing some functionality that webpack can provide

hovissimo commented 7 years ago

Not related to the stats plugin, but https://github.com/webpack/webpack-dev-server/issues/641 is also an issue with webpack-rails in multi-compiler mode.

rhys-vdw commented 7 years ago

Relevant issue unindented/stats-webpack-plugin#13.

I wonder if it might be sufficient to simply switch dependency to webpack-manifest-plugin. It seems to just output the content of stats-webpack-plugin's assetsByChunkName (asset name key to output file value hash). Although it looks like it can be configured so that the other information (publicPath) etc. can be prepended to the output file paths.

So, something like this:

stats-webpack-plugin's manifest:

{
  errors: [/*...*/],
  warnings: [/*...*/],
  version: '<some-version>',
  hash: '<some-hash>',
  publicPath: 'localhost:3000/assets',
  assetsByChunkName: {
    main: 'main.js',
    admin: 'admin.js'
  },
  assets: [{ name: 'main.js', size: 234 }, { name: 'admin.js', size: 234 }],
  chunks: [/*...*/],
  chunkNames: [/*...*/],
  children: [/*...*/]
}

webpack-manifest-plugin's manifest:

{
  main: 'localhost:3000/assets/main.js',
  admin: 'localhost:3000/assets/admin.js'
}

So provided all we care about is publicPath and actual mapping of asset to public filename this should be fine. And as @RyanS pointed out, there is support for a shared cache object.

rhys-vdw commented 7 years ago

Oh, totally missed this:

    new StatsPlugin('manifest.json', {
      // We only need assetsByChunkName
      chunkModules: false,
      source: false,
      chunks: false,
      modules: false,
      assets: true
    })]

Perfect.