I’m working on a Vite project and I need to exclude certain CSS files from the build process. These CSS files are located in the node_modules directory, and I don’t want them to be included in the final build output.
I’ve tried using the external option in the rollupOptions configuration to exclude JavaScript modules, but it doesn’t seem to work for CSS files. Here is my current vite.config.js setup:
// vite.config.js
import { defineConfig } from 'vite';
const disableStylings = process.env.VITE_APP_STYLES_ENABLED == "false";
const excludeStylings = disableStylings
? [
"./node_modules/@module-here/dist/assets/css/styles.css",
"./node_modules/@module-here/dist/assets/themes/<brand-here>/styles.css",
]
: [];
export default defineConfig({
...
build: {
rollupOptions: {
external: excludeStylings
}
}
});
Expected output is that when the VITE_APP_STYLES_ENABLED is FALSE, it should not add the content of the styles in the build, and when it is TRUE, it should include the contents of the styles in the CSS file.