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

@novlan/postcss-plugin-remove-selector

v0.1.6

Published

<p align="center"> <img src="https://img.shields.io/npm/dw/@novlan/postcss-plugin-remove-selector"> <img src="https://img.shields.io/npm/unpacked-size/@novlan/postcss-plugin-remove-selector"> <img src="https://img.shields.io/npm/v/@novlan/postcss-pl

Readme

移除选择器

可用于移除三方库中的不需要的样式,从而减小包体积。

1. 作者

novlan1

2. 如何使用

安装

pnpm add @novlan/postcss-plugin-remove-selector -D

简化模式(推荐)

通过 mode 指定预设,只需关注 used/unused,无需手动配置 fileselectorPattern

import { defineConfig } from 'vite';
import { postcssPluginRemoveSelector } from '@novlan/postcss-plugin-remove-selector';

export default defineConfig({
  css: {
    postcss: {
      plugins: [
        postcssPluginRemoveSelector({
          mode: 'tdesign',
          used: ['home', 'chat', 'user', 'add', 'search', 'close'],
        }),
      ],
    },
  },
});

使用 customUsed / customUnused 可在预设基础上增量追加,不会覆盖预设中已有的列表:

postcssPluginRemoveSelector({
  mode: 'tdesign',
  // 在 tdesign 预设默认的 used 列表上,额外追加 'star' 和 'heart'
  customUsed: ['star', 'heart'],
  // 从结果中额外移除 'loading'
  customUnused: ['loading'],
})

标准模式

通过 list 数组传入完整配置,适用于需要匹配多个文件的复杂场景:

import { defineConfig } from 'vite';
import { postcssPluginRemoveSelector } from '@novlan/postcss-plugin-remove-selector';
import {
  TDESIGN_ICON_REMOVE_SELECTOR
} from '@novlan/postcss-plugin-remove-selector/lib/tdesign-uniapp-icon';


export default defineConfig({
  css: {
    postcss: {
      plugins: [postcssPluginRemoveSelector(TDESIGN_ICON_REMOVE_SELECTOR)],
    },
  },
});

3. 类型

插件支持两种配置方式,传入 SimpleOptions(简化模式)或 Options(标准模式)均可。

SimpleOptions(简化模式)

| 属性 | 类型 | 是否必填 | 说明 | | --- | --- | --- | --- | | mode | 'tdesign' | 否 | 预设模式,设置后自动使用对应的 fileselectorPattern 默认值 | | file | RegExp \| string | 否 | 文件匹配规则。使用 mode 时可省略 | | used | string[] | 否 | 正在使用的图标名称列表,这些图标会被保留 | | unused | string[] | 否 | 未使用的图标名称列表,这些图标会被移除 | | customUsed | string[] | 否 | 增量追加到 used 列表(不覆盖预设或已有的 used) | | customUnused | string[] | 否 | 增量追加到 unused 列表(不覆盖预设或已有的 unused) | | selectorPattern | RegExp | 否 | 选择器匹配模式。使用 mode 时可省略 | | debug | boolean | 否 | 是否开启调试模式 |

modefile 至少需要指定一个。当 modefile/selectorPattern 同时指定时,file/selectorPattern 优先。

Options(标准模式)

| 属性 | 类型 | 是否必填 | 说明 | | --- | --- | --- | --- | | list | FileConfig[] | 是 | 配置列表 | | debug | boolean | 否 | 是否开启调试模式 |

FileConfig

| 属性 | 类型 | 是否必填 | 说明 | | --- | --- | --- | --- | | file | RegExp \| string | 是 | 文件匹配规则,可以是字符串或正则表达式 | | used | string[] | 否 | 正在使用的图标名称列表,这些图标会被保留 | | unused | string[] | 否 | 未使用的图标名称列表,这些图标会被移除 | | customUsed | string[] | 否 | 增量追加到 used 列表(不覆盖已有的 used) | | customUnused | string[] | 否 | 增量追加到 unused 列表(不覆盖已有的 unused) | | selectorPattern | RegExp | 否 | 选择器匹配模式,只处理匹配该模式的选择器 |

内置预设

| mode | 说明 | 默认 file | 默认 selectorPattern | | --- | --- | --- | --- | | tdesign | TDesign UniApp 图标减包 | /[@/]tdesign[/]uniapp[/]dist[/]icon[/]icon\.[css\|vue]/ | /^\.t-icon-[\w-]+:before$/ |

4. 更新日志

点此查看

5. 效果

tdesign-uniapp-starter 为例,使用此插件,可使小程序大小减少138KB,约95.8%

使用前:

使用后: