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

grass-loader

v0.0.3

Published

Used to precompile garss templates

Readme

grass-loader 用于编译 grass 模板

options

| 属性 | Description | Type | Default | |------------|-------------|------|---------| | lib | 需要用到的 grass 库 | string | @rustle/grass | | needGrass | 是否自动 import grass | boolean | false |

template 字符与注释

用两种方法导出 template,通过注释的方式,会把需要的目标方法或字符串替换到特定的注释地方

  1. template method
// #temp method
/* #temp method */

可以简写为:

// #temp
/* #temp */
  1. template string
// #temp string
/* #temp string */

demo:

<template>
  <div></div>
<template/>

<script>
export default function C () {
  return // #temp string
}
</script>

阻止编译

对于不想要参与编译的文件,可以通过 // #no compile 来阻止编译,但这行阻止编译的注释只能放在文件的最前面 demo:

// #no compile
...

几种 grass 文件的格式

  1. 一种为 templatescript 标签都齐全的文件格式,这个时候 template 注释才有作用
  2. 如果只有 template 标签,那么这个标签会默认当成一个无状态组件,这个时候有两个属性供你使用,namestyleSrc
<!-- name 为组件的名称 -->
<!-- styleSrc 为需要的 css 文件,需要开启 cssmodules, 这样就可以配合 grass 使用 styleName -->
<template name='cm' styleSrc='./style.css'>
  <div styleName='xx'></div>
</template>
  1. 如果只有 script 标签,那么会作为纯 js 文件来处理,但,needGrass 配置同样生效
  2. 对于纯 js 文件, templatescript 标签都不存在的情况下,会跳过编译,needGrass 配置将不会生效

使用

demo:

  {
    test: /\.grs$/,
    use: [
      {
        loader: 'grass-loader',
        options: {
          needGrass: true,
        },
      },
    ],
    exclude: /node_modules/,
  }

扩展

多以可以在 grs 文件中获得 template 字符串,当然可以可以进行更改

<template>
  <div></div>
</template>

<script>
  const temp = (/* #temp string */)

  changeTemplate(temp)

  function changeTemplate (t) {
    console.log(t)
    ...
  }
</script>