Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set faceModuleId for manual chunks #3497

Closed
LarsDenBakker opened this issue Apr 12, 2020 · 6 comments
Closed

Set faceModuleId for manual chunks #3497

LarsDenBakker opened this issue Apr 12, 2020 · 6 comments

Comments

@LarsDenBakker
Copy link
Contributor

Feature Use Case

When performing logic on rendered chunks, it would be useful to be able to identify them. Using manual chunks we can place some code in a separate chunk, but we need a way to identify them.

Feature Proposal

faceModuleId can be used for regular chunks, it would be nice to be able to use this for manul chunks too.

See this reproduction where the faceModuleId is not set for the manual chunk: https://repl.it/repls/WigglySpiffyDatabase

@lukastaegert
Copy link
Member

A facadeModuleId is not about the content of a chunk. Instead, it describes which module signature a chunk tries to replicate with its exports. A manualChunk does not try to replicate a module. As a matter of fact, it can be a conglomerate of dozens of modules and their dependencies. That’s why it does not make sense to add this to a manual chunk. On the other hand, you can see which modules are contained in a chunk by checking chunk.modules. Is this not enough for your purposes? Do you need the exact modules used to define the chunk?

@LarsDenBakker
Copy link
Contributor Author

My use case is for plugins which transform code in the renderChunk hook, like terser and the new babel .generated option. I'd like to be able to exclude some chunks from these plugins, and I need some way to identify manually created chunks. It seemed like faceModuleId could be it. Checking which modules are inside a chunk might not be something that can easily be fit into an excludes option.

@lukastaegert
Copy link
Member

But if there is just not one module to define a manual chunk but many, it does not really help, does it? In the best case, you could get an array or a Set of ids. And we would need to add a new property for that.

@LarsDenBakker
Copy link
Contributor Author

If you're defining a manual chunk you're already in control of what goes in, so ideally you'd be able to refer to these chunks by the name you gave it later on and tell plugins to exclude it.

If they're not manual chunks I agree anything could be in there, so it's hard to filter on that.

@lukastaegert
Copy link
Member

For manual chunks, the name property will always be the name that you gave to the chunk as it was written in the manualChunks option. This name does not need to be unique as it is possible to have a regular entry chunk with the same name, but it will be unique among manual chunks. It would assume this is enough for an excludes option? I.e.

export default {
  input: {
    // created chunk will have name "my-name" and facadeModuleId "main.js"
    'my-name': 'main.js',
    // created chunk will have name "other-entry" and facadeModuleId "other.js"
    'other-entry': 'other.js',
  },
  manualChunks: {
    // created chunk will have name "my-name" and facadeModuleId null
    'my-name': ['file-a.js', 'file-b.js'],
    // created chunk will have name "manual" and facadeModuleId null
    'manual': ['file-c.js']
  },
  ...
}

@LarsDenBakker
Copy link
Contributor Author

Name is perfect for this use case, I was testing this in the REPL and I just [Getter] in gray for the name field so it did not stick out to me. I thought it only had the generated filename with the hash. I'll an file issue for terser and babel to see if they want to use this.

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

No branches or pull requests

2 participants