How do you use browser mode with React components that have LESS stylesheets? #9453
-
|
I'm testing out browser mode for the first time and I have it working for a very simple React component (with no styles). However, when I try to run a test for a component with a LESS stylesheet, I get this error: Basically, here's what's happening:
Here's an example of what the stylesheet looks like: You may be wondering how this ends up working at all when building our app. To achieve that, we use I tried using this same approach in my Vitest config, but it didn't help. How can I get LESS stylesheets (with imports) to work in browser mode? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
|
Vitest's underlying transform/resolution logic is based on Vite, so you likely need to port your esbuild plugin to Vite plugin (likely both lessLoader and npmImportPlugin). |
Beta Was this translation helpful? Give feedback.
-
|
@kgetz-arista vitest browser mode uses vite under the hood, so you need to pass your less plugin through vite's css config, not esbuild's. // vitest.config.ts
import NpmImportPlugin from 'less-plugin-npm-import';
export default defineConfig({
css: {
preprocessorOptions: {
less: {
plugins: [new NpmImportPlugin({ prefix: '~' })],
},
},
},
test: {
browser: { /* your existing browser config */ },
},
});one thing though -- the |
Beta Was this translation helpful? Give feedback.
Ah, I think I actually spoke too soon. I forgot that we use these same kinds of imports in our Vite apps, so I tracked down our shared config and realized that the magic incantation for the config is slightly different. This works in Vitest too: