Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vitejs treat all .scss files as css modules

I am working with a legacy package in a monorepo and am including in the optimizeDeps array - is it possible to tell Vite to treat all .scss files it sees as CSS Modules files?

Originally asked in the vite discord: https://discord.com/channels/804011606160703521/1217522070343254016

The problem is that this legacy package has all its css modules files as plain .scss files instead of .module.scss which vite expects, and so I see this error:

The requested module '/@fs/Users/jakxz/go/src/.../components/fields/EditableField/EditableField.scss' does not provide an export named 'default''

EditableField.js is a compiled ESM react component that attempts to do

import styles from './EditableField.scss';
like image 565
JaKXz Avatar asked Jan 20 '26 12:01

JaKXz


1 Answers

By configuring vite.config.js file like below, all .scss files will be treated as CSS Modules files, regardless of their file extension:

// vite.config.js
export default {
  optimizeDeps: {
    include: ['**/*.scss'], // Include all .scss files
  },
  css: {
    modules: {
      // Enable CSS Modules for all .scss files
      localsConvention: 'camelCaseOnly',
    },
  },
};
like image 110
jepozdemir Avatar answered Jan 22 '26 05:01

jepozdemir



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!