Skip to content

How to extract the id mappings object for CSS modules? #185

Open
@ecommpro

Description

@ecommpro

I'm using CSS modules and server side rendering. I need to extract to a file the class mappings for my modules:

:local(.myClass) {
    background: red;
}
:local .myClass {
    color: green;
}
:local(.myClass .otherClass) {
    color: blue;
}

This creates the following code in the bundled js file:

/***/ (function(module, exports, __webpack_require__) {

eval("// extracted by extract-css-chunks-webpack-plugin\nmodule.exports = {\"myClass\":\"src-main__myClass--1e7fN\",\"otherClass\":\"src-main__otherClass--NQhbn\"};\n\n//# sourceURL=webpack:///./src/main.css?./node_modules/extract-css-chunks-webpack-plugin/dist/loader.js??ref--4-1!./node_modules/css-loader/dist/cjs.js??ref--4-2!./node_modules/postcss-loader/src!./node_modules/sass-loader/lib/loader.js");

/***/ }),

I need the contents of the eval on a separated file so I can read it from a server side language.

I'm not sure where's the best place to extract this informacion. I think I could hack the css-loader loader to retrieve the mappings, but maybe it makes more sense doing this job on extract-css-chunks-webpack-plugin, because it's extract-chunks related.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions