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

@json_vite_plugin/css_global

v1.2.2

Published

**Vite Plugin CSS Global**

Downloads

31

Readme

Vite Plugin CSS Global

英文文档

简介

Vite Plugin CSS Global 是一个 Vite 插件,用于全局注入 Less、SCSS 或 Sass 全局文件, 功能类似于 webpack 中使用 additionalData 注入全局文件, 但是你只需要传入你需要注入的文件路径即可。vue 文件也可用。

安装

npm install --save-dev @json_vite_plugin/css_global

或者

yarn add --dev @json_vite_plugin/css_global

或者

pnpm add @json_vite_plugin/css_global -D

用法

在你的 vite.config.js 文件中,添加以下代码:

import { defineConfig } from 'vite';
import cssGlobal from '@json_vite_plugin/css_global';

export default defineConfig({
  plugins: [
    cssGlobal({
      less: [], // 需要注入的less文件
      sass: [], // 需要注入的sass文件
      scss: [], // 需要注入的scss文件
      exclude: [], // 过滤掉的文件, 写哪些文件不需要注入全局文件
      isVue: false // 如果你需要在 vue 文件中注入就填true
    }),
  ],
});

你也可以在你的 vite.config.ts 文件中,添加以下代码:

import { defineConfig } from 'vite';
import cssGlobal from '@json_vite_plugin/css_global';

export default defineConfig({
  plugins: [
    cssGlobal({
      less: [], // 需要注入的less文件
      sass: [], // 需要注入的sass文件
      scss: [], // 需要注入的scss文件
      exclude: [], // 过滤掉的文件, 写哪些文件不需要注入全局文件
      isVue: false // 如果你需要在 vue 文件中注入就填true
    }),
  ],
});

选项

| 选项 | 类型 | 默认值 | 描述 | | --------- | ---------- | ------- | ------------------------ | | exclude | string[] | [] | 排除的文件或目录。 | | less | string[] | [] | 要全局注入的 Less 文件。 | | scss | string[] | [] | 要全局注入的 SCSS 文件。 | | sass | string[] | [] | 要全局注入的 Sass 文件。 | | isVue | bool | false | 是否为 vue 项目。 |

示例

以下是一个使用 Vite Plugin CSS Global 的示例:

// vite.config.js
import { defineConfig } from 'vite';
import cssGlobal from 'vite-plugin-css-global';

export default defineConfig({
  plugins: [
    cssGlobal({
      less: ['src/styles/global.less'],
      scss: ['src/styles/global.scss'],
      sass: ['src/styles/global.sass'],
      exclude: [
        'src/styles/global.less',
        'src/styles/global.scss',
        'src/styles/global.sass'
      ],
      isVue: true
    }),
  ],
});

在这个示例中,我们使用 Vite Plugin CSS Global 来全局注入 src/styles/global.lesssrc/styles/global.scsssrc/styles/global.sass 文件。

然后,我们在 lessscsssass 文件中使用了全局文件中的变量或方法, 不再需要去lessscsssass文件中单独引用全局文件。

反馈 如果有bug反馈请发送邮箱到 [email protected]