Closed zalishchuk closed 7 months ago
@alexander-akait the reason is that layers
are not included into plugin options validation schema, and even if I remove the validation manually it doesn't work as expected.
ValidationError: Invalid options object. Mini CSS Extract Plugin has been initialized using an options object that does not match the API schema.
- options has an unknown property 'layer'. These properties are valid:
object { filename?, chunkFilename?, experimentalUseImportModule?, ignoreOrder?, insert?, attributes?, linkType?, runtime? }
The solution I found for myself is:
function _wrapExternalsLayer(rawExternals) {
const externals = rawExternals.byLayer;
return (ctx, callback) => {
const issuerLayer = ctx.contextInfo?.issuerLayer;
if (issuerLayer) {
const moduleName = ctx.request.split('/')[0];
const externalResult = externals[issuerLayer]?.[moduleName];
if (externalResult) return callback(null, externalResult);
}
callback();
};
}
// webpack.config.js
externals: _wrapExternalsLayer({
byLayer: {
'bundle-externals': {
'my-lib': 'myLib',
},
},
}),
Ah, didn't notice this layer
option is for the loader, not the plugin, but still doesn't solve the problem I mentioned above.
Yeah, you need to pass this to loader https://github.com/webpack-contrib/mini-css-extract-plugin/blob/master/src/loader-options.json#L28
The feature I am trying to implement is filtering entry chunks from which CSS will be extracted.
Can you clarify?
Because in this case you will have the first chunk extracted and the second chunk with CSS inside JS, do you expect it?
To be honest, I don't think you're going in the right direction. You can use multi compiler mode for it. Maybe I missing something, so can you create a small repo/example and show you what you expected?
Closing due to inactivity. Please test with latest version and feel free to reopen if still regressions. Thanks!
Feature Proposal
The feature I am trying to implement is filtering entry chunks from which CSS will be extracted. Any chance it can be done using
filename
function syntax andpathData
argument in it?Feature Use Case
Two same entry points, with different names, but one of them does not have
externals
in it. Done with the help of webpack5layers
feature. So as a result, we have like 2 identical.css
files exported with different names, but want to have only one.HtmlWebpackPlugin
has this feature and it is very useful.Please paste the results of
npx webpack-cli info
here, and mention other relevant information