MCPcopy Index your code
hub / github.com/nuxt-modules/style-resources

github.com/nuxt-modules/style-resources @v2.0.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v2.0.0 ↗ · + Follow
4 symbols 20 edges 12 files 0 documented · 0% 1 cross-repo links updated 12d agov2.0.0 · 2023-10-08★ 59822 open issues

Browse by type

Functions 3 Types & classes 1
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Style Resources for Nuxt 3 - Nobody likes extra @import statements!

npm version npm downloads Codecov License

Nuxt 2 is supported with @nuxtjs/style-resources@^1, documentation is on v1 branch.

If you are using Vite, this module is not needed.

You can use the css.preprocessorOptions instead.

📖 Release Notes

Features

  • Share variables, mixins, functions across all style files (no @import needed)
  • Support for SASS, LESS and Stylus
  • Aliases (~/assets/variables.css) and globbing as supported
  • Support for hoisting @use imports
  • Compatible with Nuxt's build.styleResources (and will take them over directly if included!)
  • Blazing fast:tm:

Warning

Do not import actual styles. Use this module only to import variables, mixins, functions (et cetera) as they won't exist in the actual build. Importing actual styles will include them in every component and will also make your build/HMR magnitudes slower. Do not do this!

Setup

  • If not already present, add the dependencies you need for SASS/LESS/Stylus (depending on your needs)
  • SASS: yarn add sass-loader sass (for Nuxt 2 use: sass-loader@10)
  • LESS: yarn add less-loader less
  • Stylus: yarn add stylus-loader stylus
  • Add @nuxtjs/style-resources dependency using yarn or npm to your project (yarn add -D @nuxtjs/style-resources)
  • Add @nuxtjs/style-resources to buildModules section of nuxt.config.js:
export default {
  buildModules: [
    '@nuxtjs/style-resources',
  ],

  styleResources: {
   // your settings here
   sass: [],
   scss: [],
   less: [],
   stylus: [],
   hoistUseStatements: true  // Hoists the "@use" imports. Applies only to "sass", "scss" and "less". Default: false.
  }
}

Examples

LESS Example

nuxt.config.js:

export default {
  css: ['~assets/global.less'],
  buildModules: ['@nuxtjs/style-resources'],
  styleResources: {
    less: './assets/vars/*.less'
  }
}

assets/global.less

h1 {
  color: @green;
}

assets/vars/variables.less

@gray: #333;

assets/vars/more_variables.less

@green: #00ff00;

pages/index.vue

<template>




    <h1>Test</h1>
    <test/>



</template>

<script>
import Test from '~/components/Test'

export default {
  components: { Test }
}
</script>

components/Test.vue

<template>



    Test



</template>

<style lang="less">
  .ymca {
    color: @gray; // will be resolved to #333
  }
</style>

SCSS Example

nuxt.config.js:

export default {
  buildModules: ['@nuxtjs/style-resources'],
  styleResources: {
    scss: [
      './assets/vars/*.scss',
      './assets/abstracts/_mixins.scss' // use underscore "_" & also file extension ".scss"
      ]
  }
}

Instead of './assets/abstracts/_mixins.scss' you can use also '~assets/abstracts/_mixins.scss'

assets/vars/_colors.scss

$gray: #333;

assets/abstracts/_mixins.scss

@mixin center() {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate3d(-50%, -50%, 0);
}

components/Test.vue

<template>



    Test



</template>

<style lang="scss">
  .ymca {
    @include center; // will be resolved as position:absolute....
    color: $gray; // will be resolved to #333
  }
</style>

License

Inspired by nuxt-sass-resources-loader.

MIT License

Copyright (c) Alexander Lichter

Extension points exported contracts — how you extend this code

Core symbols most depended-on inside this repo

Shape

Function 3
Interface 1

Languages

TypeScript100%

Modules by API surface

src/module.ts4 symbols

Used by 1 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add style-resources \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page