shellscape / webpack-manifest-plugin

webpack plugin for generating asset manifests
MIT License
1.44k stars 185 forks source link

Option to not use `publicPath` or possibly override it #130

Closed pgilad closed 6 years ago

pgilad commented 6 years ago

Currently publicPath is taken from webpack output.publicPath, while this may work, in our use case we don't want to add the publicPath. There is currently no way to override it

macisi commented 6 years ago

I'm using the following code to remove publicPath in manifest.json 😊

  new ManifestPlugin({
      map(asset) {
        return Object.assign(asset, {
          path: asset.path.replace(output.publicPath, ''),
        });
      },
  })
pgilad commented 6 years ago

Thanks, I use this:

// work around publicPath being added to rev-manifest
if (file.path.startsWith(publicPath)) {
    file.path = file.path.substr(publicPath.length);
}

But this sucks, I'd rather it not added in the first place

mastilver commented 6 years ago

On this one, I'm not sure yet...

I don't think adding publicPath back would be a bad idea Can you send a PR to add it back (with tests and appropriate docs update)?

Can you give me more context?

joaovieira commented 6 years ago

@mastilver I'd just like to use it exactly like this https://github.com/webdeveric/webpack-assets-manifest#add-your-cdn to prefix the values with the CDN host in production.

mastilver commented 6 years ago

yes, I think we should add it back...

I think it's annoying enough peoples...

Do you want to send a PR @joaovieira ?

joaovieira commented 6 years ago

@mastilver cool! I'm a little busy right now, but I'm happy to have a look in a couple of days when I'm a bit more free if no one picked it up before!

(Adding to TODO list) 👍

Would you be able to point the commit where it was removed if not asking too much?

mastilver commented 6 years ago

Here's the PR: https://github.com/danethurber/webpack-manifest-plugin/pull/80

joaovieira commented 6 years ago

Dough, never mind my use case! I don't need it after all 🤦‍♂️ What I really need/want is to change the output.publicPath for all the rewiring, not just the manifest. This is so async chunks/modules (loaded internally by webpack) use that as well. It's working perfectly.

Re: https://webpack.js.org/configuration/output/#output-publicpath

third774 commented 6 years ago

@mastilver - my use case is to read certain files on the server side an inline them into the html document that gets served. I rely on the manifest to know what file to read in, and do not want the publicPath to be present since the files simply exist within my dist folder.

mastilver commented 6 years ago

@third774 Would you be fine, if you have to use it that way:

new ManifestPlugin({
  publicPath: ''
})
jtomaszewski commented 6 years ago

We have the same problem as @third774 . Your solution @mastilver would work for us perfectly. For now, we're using @pgilad workaround.

mastilver commented 6 years ago

available on v2