Skip to content
This repository has been archived by the owner on Oct 2, 2019. It is now read-only.

Support for multiple chunks #79

Open
ketan opened this issue Feb 12, 2017 · 3 comments
Open

Support for multiple chunks #79

ketan opened this issue Feb 12, 2017 · 3 comments

Comments

@ketan
Copy link

ketan commented Feb 12, 2017

It looks like this gem breaks when using multiple chunks.

The fix seems to be to change Webpack::Rails::Manifest.asset_paths to the following implenentation —

        def asset_paths(source)
          raise WebpackError, manifest["errors"] unless manifest_bundled?

          if manifest["entrypoints"][source] && paths = manifest["entrypoints"][source]['assets']
            # # Can be either a string or an array of strings.
            # # Do not include source maps as they are not javascript
            [paths].flatten.reject { |p| p =~ /.*\.map$/ }.map do |p|
              "/#{::Rails.configuration.webpack.public_path}/#{p}"
            end
          else
            raise EntryPointMissingError, "Can't find entry point '#{source}' in webpack manifest"
          end

        end
@mipearson
Copy link
Owner

Huh. Could have sworn we supported multiple chunks. Thanks for the issue.

Can you please submit this in a pull request?

@ketan
Copy link
Author

ketan commented Mar 2, 2017

I'm not sure if this will break webpack 1.x compatibility in any way...

Based on this spec, it looks like the manifest.json is supposed to look like —

{
  "errors": [],
  "assetsByChunkName": {
    "entry1": [ "entry1.js", "entry1-a.js" ],
    "entry2": "entry2.js"
  }
}

However the actual manifest.json on my project looks like. Note that assetsByChunkName is not an array.

{
  "assetsByChunkName": {
    "single_page_apps/agents": "single_page_apps/agents-e7560caa94a75cbca3b1.js",
    "vendor-and-helpers.chunk": "vendor-and-helpers.chunk-22b0993852189b6bf4ca.js"
  },
  "assets": [
    {
      "name": "single_page_apps/agents-e7560caa94a75cbca3b1.js",
      "chunkNames": [
        "single_page_apps/agents"
      ]
    },
  ],
  "entrypoints": {
    "single_page_apps/agents": {
      "assets": [
        "vendor-and-helpers.chunk-22b0993852189b6bf4ca.js",
        "single_page_apps/agents-e7560caa94a75cbca3b1.js"
      ]
    }
  }
}

@ketan
Copy link
Author

ketan commented Jun 22, 2017

@mipearson — may I get some thoughts on my comment above?

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

2 participants