zeokku / vite-plugin-vue-css-modules

✨ Ultimate solution for using CSS modules without any hassle.
17 stars 0 forks source link

Recipe for Nuxt integration #7

Closed IlyaSemenov closed 1 year ago

IlyaSemenov commented 1 year ago

Is there a recipe to use this with Nuxt 3?

Lutymane commented 1 year ago

@IlyaSemenov Hello! I am not too familiar with Nuxt. Could you try to specify it inside of nuxt-config/vite with enforce: pre option and see if it works?

IlyaSemenov commented 1 year ago

It fails to starts: https://stackblitz.com/edit/nuxt-starter-r5dkaz?file=app.vue,nuxt.config.ts

ERROR  You gave us a visitor for the node type requeueComputedKeyAndDecorators but it's not a valid type

  at verify (node_modules/vite-plugin-vue-css-modules/node_modules/@babel/traverse/lib/visitors.js:92:13)
  at explode (node_modules/vite-plugin-vue-css-modules/node_modules/@babel/traverse/lib/visitors.js:26:3)
Lutymane commented 1 year ago

@IlyaSemenov It was an issue with babel libs versions. I've updated them along with some qol changes. Update plugin to the latest 3.1.3 version. It should work now

// app.vue
<template>
  <div class="test">hello</div>
</template>

<style module>
.test {
  color: red;
}
</style>
// nuxt.config
import { cssm } from "vite-plugin-vue-css-modules";

export default defineNuxtConfig({
  vite: {
    plugins: [cssm()],
  },
});
IlyaSemenov commented 1 year ago

I confirm that it works now: https://stackblitz.com/edit/nuxt-starter-cp8xnr?file=app.vue,nuxt.config.ts

Thanks!

Lutymane commented 1 year ago

@IlyaSemenov great! Just make sure to enable scriptTransform if you're using removeCssModulesChunk