A Babel plugin that transforms CSS imports by processing them through PostCSS, enabling CSS Modules to generate JavaScript objects mapping class names to hashed strings. At version 0.3.0, it supports both synchronous and asynchronous PostCSS plugins and uses postcss-load-config for configuration. Unlike alternatives like css-modules-transform or css-modules-require-hook, it works with any PostCSS plugin and integrates with babelify for Browserify. It does not include CSS in the output; separate CSS extraction is required. Active development appears stalled, with no major releases since 2018, and it depends on PostCSS v6.
npm install babel-plugin-transform-postcssVerified import paths — ran on the pinned version, not inferred.
Babel configuration with the plugin and a postcss.config.js using postcss-modules to extract CSS module class names into JS object.
Ensure a separate build step for CSS (e.g., postcss-cli) is in place alongside this Babel plugin.
Manually delete the cache directory (/tmp/bptp-*) when changing PostCSS configuration.
Use a more actively maintained plugin like 'devsnek/babel-plugin-transform-css-modules' or consider upgrading PostCSS manually (requires fork).
Install postcss-load-config: npm install --save-dev postcss-load-config
Run: npm install --save-dev postcss-load-config
Use an older version of postcss-modules that supports PostCSS 6 (e.g., v1.1.0), or switch to a different Babel plugin.
Add a CSS loader to your bundler (e.g., css-loader for Webpack) to handle .css files, or ensure the transform runs before bundling.