npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@wattanx/style-resources

v1.0.0

Published

@nuxtjs/style-resources module compatible with Nuxt 3

Downloads

65

Readme

Style Resources Module compatible with Nuxt 3

For vite, use this one.

https://vitejs.dev/config/shared-options.html#css-preprocessoroptions

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
  • 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
    • LESS: yarn add less-loader less
    • Stylus: yarn add stylus-loader stylus
  • Add @wattanx/style-resources dependency using yarn or npm to your project
  • Add @wattanx/style-resources to modules section of nuxt.config.ts:
export default defineNuxtConfig({
  modules: ["@wattanx/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.ts:

export default defineNuxtConfig({
  css: ["@/assets/global.less"],
  modules: ["@wattanx/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>
  <div>
    <!-- This h1 will be green -->
    <h1>Test</h1>
    <Test />
  </div>
</template>

components/Test.vue

<template>
  <div class="test">Test</div>
</template>

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

SCSS Example

nuxt.config.ts:

export default defineNuxtConfig({
  modules: ["@wattanx/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>
  <div class="test">Test</div>
</template>

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

Development

# Install dependencies
pnpm install

# Generate type stubs
pnpm dev:prepare

# Develop with the playground
pnpm dev

# Build the playground
pnpm dev:build

# Run ESLint
pnpm lint

# Run Vitest
pnpm test
pnpm test:watch

# Release new version
pnpm run release