faceyspacey / faceyspacey/extract-css-chunks-webpack-plugin

How to extract the id mappings object for CSS modules?

Open
#185 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
693
Forks
83
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.