Description
Feature Proposal
Feature Use Case
I want to use webpack to bundle npm packages and component libraries that come with css/scss.
Currently, mini-css treats css resources as side effects. Which makes sense when webpack is the consumer build, but does not make sense if webpack is a library build.
Id like to still process styles, but leave the require statement as an external.
example:
require('./button.scss') -> becomes document.createElement(handleSideEffectDep)
for library builds id like to
require('./button.scss') -> require('./dist/248.css') so that the consumer build manages the side effect and i can ship component libraries that require their own css, but do not handle DOM injection.
Currently you would have to use style-loader which is not optimal. The alternative avaliable is using something like rollup which does not attempt to bundle side effects of a library, instead it treats it like an external once emitted. Then the consumer build is responsible for loading the side effect and its runtime requirements to inject styles.
Current output:
;// CONCATENATED MODULE: ./src/component.css
// extracted by mini-css-extract-plugin
/* harmony default export */ const component = ({"test-css-loader":"gj_ovF"});
desired output
;// CONCATENATED MODULE: ./src/component.css
// extracted by mini-css-extract-plugin
require('dist/248.css') // REFERENCE MODULE: ./src/component.css
/* harmony default export */ const component = ({"test-css-loader":"gj_ovF"});
If i add a very primitive loader to the start of the loader chain, it kind of works (though resolution paths would be incorrect. But that could be fixed.
module.exports = function(content,map,meta) {
// console.log(this.resourcePath);
// console.log(content);
// content.source = 'test'
const result = `__non_webpack_require__('${this.resourcePath}');
${content}`
console.log(result)
this.callback(null,result)
}
that would process the file as i need, and still load a require() into the file as a side effect - however this should point to main.css to pair with main.mjs/js