module-builder icon indicating copy to clipboard operation
module-builder copied to clipboard

Vue SFC vite.css.preprocessorOptions.scss.additionalData cannot run `nuxt-module-build`

Open homersimpsons opened this issue 6 months ago • 1 comments

I'm writing a Nuxt Module, in this module I want to use <style> directly in my vue Single File Component.

I have some mixins, functions and variables defined in SCSS and I want to inject them in every <style> so I used the vite.css.preprocessorOptions.scss.additionalData:

extendViteConfig((config) => {
  config.css = defu(config.css || {}, { preprocessorOptions: { scss: { additionalData: '' } } });
  config.css.preprocessorOptions.scss.additionalData += '\n@import "src/assets/imports.scss";\n'
});

This works fine when I use nuxi dev playground, but it fails to compile with nuxt-module-build: SASS cannot find the declared variables / functions.

It looks like this is "expected" as nuxt-module-buidler does not instantiate the module, but I cannot seem to find any reference on how to register my additionalData.

I saw it was possible to write a build.config.ts with a defineBuildConfig but I was not able to find the correct options to use.

  1. Is this behavior expected ?
  2. How can I mimic / replace my module config with a build config so nuxt-module-buidler works ?

References:

  • https://github.com/nuxt/module-builder/issues/87
  • https://github.com/unjs/mkdist
  • https://github.com/unjs/unbuild

homersimpsons avatar Dec 04 '23 16:12 homersimpsons

You should look at the solution described here, which seem to address exactly your problem https://github.com/nuxt/module-builder/issues/90

ennioVisco avatar Apr 28 '24 12:04 ennioVisco