A Webpack loader that extracts CSS custom properties (variables) from CSS files and makes them available as a JavaScript object map. Version 2.0.2 is the latest stable release. It only supports variables defined on the `:root` selector and requires a Webpack-based build setup. Unlike CSS-modules or other approaches, this loader provides a simple key-value export of CSS variable names to their string values, facilitating dynamic theme or configuration use.
npm install css-variables-loaderVerified import paths — ran on the pinned version, not inferred.
Demonstrates importing a CSS file with css-variables-loader and logging the extracted variables object.
Ensure all desired CSS custom properties are declared under `:root { ... }`. Variables in other selectors or @media blocks are ignored.Use an alternative solution such as `postcss-custom-properties` with Rollup or a similar bundler-specific plugin.
Parse numeric values manually if needed: `parseInt(variables['--my-font-size'], 10)` or use a helper library.
Add the loader prefix: `import variables from 'css-variables-loader!./variables.css';`
Run `npm install --save-dev css-variables-loader`