shellscape / webpack-manifest-plugin

webpack plugin for generating asset manifests
MIT License
1.43k stars 186 forks source link

Entry files passed to generate option lack public path prefix #291

Closed rjgotten closed 1 year ago

rjgotten commented 2 years ago

Expected Behavior / Situation

The entries passed to the generate option include the public path prefix on their files and can be used to map entry name to required files to load.

Actual Behavior / Situation

The entries passed to the generate option lack the compiler's output public path prefix on their files. Before they can be used as an effective mapping from entry name to required files to load, the public path prefix needs to be added by hand.

This could be done by hardcoding it, but in meta-plugin scenarios where you develop reusable bundling logic this becomes more annoying, as in this particular scope there is no easy guaranteed way to get hold of the compiler or compilation objects other than wrapping the whole thing into a meta-plugin yourself and grabbing the public path that way.

Modification Proposal

Include the public path prefix from the compiler output settings in the entry files before they are passed to the generate option.

stale[bot] commented 1 year ago

Hey folks. This issue hasn't received any traction for 60 days, so we're going to close this for housekeeping. If this is still an ongoing issue, please do consider contributing a Pull Request to resolve it. Further discussion is always welcome even with the issue closed. If anything actionable is posted in the comments, we'll consider reopening it.

juanca commented 1 year ago

This is still an issue. I need to support multi-page Webpack + Rails + SplitChunks. For each entry, it might have 1+ associated assets.

The default behavior for webpack-manifest-plugin is a flat map of chunks to paths. However, there is not enough information to load the necessary assets per page.

I found the generate function can alleviate this by producing a better manifest. After tinkering with it for a day, there isn't a simple dynamic function to produce the correct nested manifest. I am now reducing the entries argument and prefixing the public path.

Ideally, the plugin would produce the correct manifest given the usage of split chunks. Less ideally, the arguments to generate would have enough information to produce the correct manifest.

Here is an example of my entries:

  accept_invitation: [
    'runtime-387ae54a7128ea148bfa.js',
    'vendors~accept_invitation~access_groups~account_recent_events_tab~activity_feed_page~admin-b985193cf8e1238d423f.js',
    'accept_invitation-8357aede80513b35f819.css',
    'accept_invitation-8357aede80513b35f819.js'
  ],
  access_groups: [
    'runtime-387ae54a7128ea148bfa.js',
    'vendors~accept_invitation~access_groups~account_recent_events_tab~activity_feed_page~admin-b985193cf8e1238d423f.js',
    'vendors~access_groups~account_recent_events_tab~activity_feed_page~admin-6dede358e486e7f51a6b.js',
    'access_groups-7db29b4159c1f48ab84a.css',
    'access_groups-7db29b4159c1f48ab84a.js'
  ],

Here are some example of chunks:

{
    chunk: Chunk {
      id: 0,
      ids: [Array],
      debugId: 1227,
      name: 'runtime',
      preventIntegration: true,
      entryModule: undefined,
      _modules: [SortableSet [Set]],
      filenameTemplate: undefined,
      _groups: [SortableSet [Set]],
      files: [Array],
      rendered: true,
      hash: '387ae54a7128ea148bfa4f9b6927ccab',
      contentHash: [Object: null prototype],
      renderedHash: '387ae54a7128ea148bfa',
      chunkReason: undefined,
      extraAsync: false,
      removedModules: undefined
    },
    isAsset: false,
    isChunk: true,
    isInitial: true,
    isModuleAsset: false,
    name: 'runtime.js',
    path: '/compiled/runtime-387ae54a7128ea148bfa.js'
  },
{
    chunk: Chunk {
      id: 1,
      ids: [Array],
      debugId: 1224,
      name: 'vendors~accept_invitation~access_groups~account_recent_events_tab~activity_feed_page~admin',
      preventIntegration: false,
      entryModule: undefined,
      _modules: [SortableSet [Set]],
      filenameTemplate: undefined,
      _groups: [SortableSet [Set]],
      files: [Array],
      rendered: true,
      hash: 'b985193cf8e1238d423ff9028514978d',
      contentHash: [Object: null prototype],
      renderedHash: 'b985193cf8e1238d423f',
      chunkReason: 'split chunk (cache group: vendors) (name: vendors~accept_invitation~access_groups~account_recent_events_tab~activity_feed_page~admin)',
      extraAsync: false,
      removedModules: undefined
    },
    isAsset: false,
    isChunk: true,
    isInitial: true,
    isModuleAsset: false,
    name: 'vendors~accept_invitation~access_groups~account_recent_events_tab~activity_feed_page~admin.js',
    path: '/compiled/vendors~accept_invitation~access_groups~account_recent_events_tab~activity_feed_page~admin-b985193cf8e1238d423f.js'
  },
nsunga commented 11 months ago

@juanca tangential/separate question: how do u get your entries mapped to the webpack assets it needs?

im assuming you have a custom generate function for the plugin?

can u share what your configuration for WebpackManifestPlugin looks like?

im assuming ur using Webpack 5