I need to configure rollup-plugin-postcss to only modify the CSS class names of certain files. I know this is possible with WebPack but I can't figure out how to do it with Rollup. Ideally I would like to give a regular expression that describes what to do with CSS files that match that criteria.
This is what my rollup.config.js looks like:
import commonjs from "@rollup/plugin-commonjs";
import resolve from "@rollup/plugin-node-resolve";
import external from "rollup-plugin-peer-deps-external";
import typescript from "rollup-plugin-typescript2";
import pkg from "./package.json";
import babel from "rollup-plugin-babel";
import sourcemaps from "rollup-plugin-sourcemaps";
import postcss from "rollup-plugin-postcss";
import static_files from "rollup-plugin-static-files";
import image from "@rollup/plugin-image";
export default {
input: "src/index.ts",
output: [
{
file: pkg.main,
format: "cjs",
sourcemap: true,
},
{
file: pkg.module,
format: "es",
sourcemap: true,
},
],
plugins: [
external(),
image(),
babel({
exclude: "node_modules/**",
plugins: ["babel-plugin-styled-components"],
}),
static_files({ include: ["./public"] }),
resolve(),
commonjs(),
typescript({
tsconfig: "tsconfig.json",
}),
sourcemaps(),
postcss({
use: ["sass"],
extract: true,
modules: true,
}),
],
external: ["react", "react-dom"],
};
I kind of figured it out. I used rollup-plugin-postcss-modules instead of rollup-plugin-postcss. This is what my rollup.config.js ended up looking like: