-
-
Notifications
You must be signed in to change notification settings - Fork 553
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
[Feature]: Support loaderContext._module.issuer
#8102
Comments
@luhc228 can you add more usage context about this api? |
Yes. In my implement, I want to get the entry of current module because I need to collect some information about the entry. For example: const entryInfo = new Map()
// loader.js
export default function loader(loaderContext, content) {
// get info, for example
const __HAS_COMPONENT__ = content.includes('components: {}')
// get the entry module
const entryModule = getEntryModule(loaderContext._module)
// collect
entryInfo.set(entryModule.name, { __HAS_COMPONENT__ })
}
function getEntryModule(_module) {
if (!_module.issuer) {
return _module
}
return getEntryModule(_module.issuer)
}
|
since a module can be imported by multi entries, I'm not sure you can get entryModule by issuer this way? |
you may need module-graph api to find all the entrypoint contains the specfic module and you may need to do it in plugin other than loader {
/**
*
* @param {import('webpack').Compiler} compiler
*/
apply(compiler){
compiler.hooks.done.tap('s', (stats) => {
const entries = [];
stats.compilation.entrypoints.forEach(entry => {
entry.chunks.forEach(chunk => {
chunk.getModules().forEach(m =>{
if(m.identifier() == your_module.identifier()){
entries.push(entry);
}
})
})
})
})
}
} |
Thanks for your advices! It seems that I don't need the |
close since it is not needed now |
What problem does this feature solve?
To align Webpack loader context.
What does the proposed API of configuration look like?
The text was updated successfully, but these errors were encountered: