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 🙏

© 2026 – Pkg Stats / Ryan Hefner

weapp-style-injector

v1.0.7

Published

Style entry injection for cross-platform mini-program and Web builds. 面向小程序与 Web 跨端构建的样式入口注入工具。

Readme

weapp-style-injector

Use weapp-style-injector/types for framework options without importing Vite or Webpack adapter implementations.

English | 简体中文

weapp-style-injector generates style entry assets for mini program builds and injects them into matching page or component styles through @import. It supports common Vite, Webpack, uni-app, Taro, and Mpx build setups.

It does not decide which files Tailwind CSS scans:

  • cssEntries lets weapp-tailwindcss identify Tailwind CSS entry files.
  • Each entry's @source directives define the candidates generated for that entry.
  • styleInjector.rules maps generated subpackage entries to target style assets.

Recommended Entries

| Scenario | Entry | | --- | --- | | Already using weapp-tailwindcss | Use the main plugin's styleInjector option | | Generic Vite plugin | weapp-style-injector/vite | | Generic Webpack plugin | weapp-style-injector/webpack | | uni-app Vite preset | weapp-style-injector/vite/uni-app | | uni-app Webpack preset | weapp-style-injector/webpack/uni-app | | Taro Vite preset | weapp-style-injector/vite/taro | | Taro Webpack preset | weapp-style-injector/webpack/taro | | Mpx Webpack preset | weapp-style-injector/webpack/mpx |

The uni-app, taro, and subpackage parser modules are internal implementation details, not public application entry points.

Using the Built-in Integration

weapp-tailwindcss already includes this package. Existing projects do not need to install or register another plugin:

import { dirname, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import uni from '@dcloudio/vite-plugin-uni'
import { defineConfig } from 'vite'
import { WeappTailwindcss } from 'weapp-tailwindcss/vite'

const projectRoot = dirname(fileURLToPath(import.meta.url))

export default defineConfig({
  plugins: [
    uni(),
    WeappTailwindcss({
      cssEntries: [
        resolve(projectRoot, 'src/main.css'),
        resolve(projectRoot, 'src/sub-normal/index.css'),
        resolve(projectRoot, 'src/sub-independent/index.css'),
      ],
      styleInjector: {
        rules: {
          'index.css': [
            'pages/**/*.css',
            'pages/**/*.wxss',
            'pages/**/*.acss',
            'pages/**/*.ttss',
            'pages/**/*.qss',
            'pages/**/*.jxss',
          ],
        },
      },
    }),
  ],
})

The uni-app preset reads subpackage roots from pages.json. The rule finds index.css inside each subpackage, emits the platform-specific entry, and prepends a relative import to matching page styles:

@import "../index.wxss";

.page-local {
  border-width: 3rpx;
}

Each Tailwind entry must still own its scan scope:

@import "tailwindcss" source(none);

@source "./pages/**/*.{vue,js,ts}";
@source not "./sub-normal/**/*";
@source not "./sub-independent/**/*";
@import "tailwindcss" source(none);

@source "./pages/**/*.{vue,js,ts}";

Main-only utilities now stay in the main entry, while normal and independent subpackage utilities stay in their own entries. Shared utilities such as text-white are expected to appear in every entry that uses them.

Standalone Usage

When weapp-tailwindcss is not in use, or when only prebuilt style entries need to be injected, register a framework preset directly:

import uni from '@dcloudio/vite-plugin-uni'
import { defineConfig } from 'vite'
import { StyleInjector } from 'weapp-style-injector/vite/uni-app'

export default defineConfig({
  plugins: [
    uni(),
    StyleInjector({
      rules: {
        'index.css': ['pages/**/*.wxss'],
        'components.css': ['components/**/*.wxss'],
      },
    }),
  ],
})

Without explicit rules, the uni-app, Taro, and Mpx presets detect common entries and make subpackage styles reference the main app style:

StyleInjector()

Use ref when the main app style reference should be explicit:

StyleInjector({
  rules: [
    [{ ref: 'app.css' }, {
      include: ['pages/**/*.wxss'],
      exclude: ['pages/legacy/**/*.wxss'],
    }],
  ],
})

Common Options

| Option | Purpose | | --- | --- | | imports | Inject fixed entries into every matching asset | | perFileImports | Resolve entries dynamically from an output file name | | rules | Map subpackage style entries to target assets | | include / exclude | Restrict assets processed by the plugin | | dedupe | Avoid inserting an existing @import; enabled by default |

Demo and Documentation