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

unplugin-condition-compile

v1.1.0

Published

条件编译插件,可以通过注释语法,使代码块针对不同情况进行可选择的编译和剔除

Downloads

4

Readme

unplugin-condition-compile

条件编译插件,可以通过注释语法,使代码块针对不同情况进行可选择的编译和剔除

安装

npm i -D unplugin-condition-compile
// rollup.config.js
import plugin, {rollup as pluginRollup} from 'unplugin-vue-components/rollup'

export default {
    plugins: [
        plugin.rollup({ /* options */}),
        pluginRollup({ /* options */})
    ],
}

目前仅调试了rollup

参数

interface ConditionCompileOption {
    target: string;
    startIncludeTag?: string;
    startExcludeTag?: string;
    endTag?: string;
}
  • target: 编译时指定的条件字符串
  • startIncludeTag: 包含条件的起始标签,默认#ifdef
  • startExcludeTag: 排除条件的起始标签,默认#ifndef
  • endif: 结束标签,默认#endif

使用

使用注释,以 #ifdef 或 #ifndef 开头,以 #endif 结尾。匹配条件可自定义

// #ifdef target1 || target2 ...
// #ifndef target1 || target2 || ...
// #endif
  • #ifdef:仅在该条件中存在
  • #ifndef:在该条件中不存在
  • #endif:结束,就近匹配
  • targetn:匹配目标,和配置项中的target匹配,可通过 || 指定多个目标(或)
// #ifdef t1 || t2
console.log('target等于t1和t2时,这块代码才会编译进去')
// endif

// #ifndef target1 || target2
console.log('target等于t1或t2时,这块代码会被剔除')
// endif

自定义语法

可以通过 startIncludeTag,startExcludeTag,endTag 配置项来自定义模板中的语法

export default {
    plugins: [
        plugin.rollup({
			target: 'wx',
            startIncludeTag: '$startIncludeTag',
            startExcludeTag: '!startExcludeTag',
			endTag: '@endTag'
		})
    ],
}
// $startIncludeTag wx
console.log('包含在wx中的code')
// @endTag

// !startExcludeTag wx
console.log('不包含在wx中的code')
// @endTag