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

vite-plugin-emt

v0.0.8

Published

emt support for vite

Downloads

30

Readme

vite-plugin-emt

emt文件支持

处理过程:

Emmet with indentations ─► Standard Emmet
                                 │
                                 ▼
                HTML ◄──── HTML Template

Requirements

Node 16+

Build

pnpm build

Usage

// vite.config.ts
import Unocss from 'unocss/vite'
import emt, { inlineStylus } from 'vite-plugin-emt'

export default {
	plugins: [
		emt(/* emt options */),
		Unocss({
			transformers: [
				inlineStylus(/* stylus options */),
				// other transformers...
			]
			// Unocss options...
		})
	]
}

Options

所有参数均可选 | 名称 | 类型 | 说明 | | ------------ | --------------------------------------------- | --------------------------------------------------------------------------- | | alwaysReload | boolean | 开发模式下,当emt文件改变后是否总是重新加载 | | classy | boolean | 启用emmet扩展语法(默认值:true) | | cssProps | Set<string> | 将集合内的元素视为CSS属性,渲染为内联样式,传入一个空的集合表示禁用内联样式 | | literal | string | emt字面量前缀,默认为emt,为空串表示禁用emt字面量 | | log | (server: ViteDevServer, file: string) => void | 日志函数,默认重新加载时输出信息到控制台 | | paths | string[] | 除root外的include搜索路径 | | read | (path: string) => string | 自定义文件读取函数 | | render | Render | 自定义模板渲染函数 | | root | string | emt文件所在根文件夹 | | templated | boolean | 为true时每个emt元素模板至多展开一次 | | tplFile | string | 自定义模板文件 | | writeHtml | boolean | 是否输出html,用于构建 |

emt环境变量

环境变量类型均为string | 名称 | 说明 | | ------------ | --------------------- | | REQUEST_PATH | 请求的emt文件完整路径 |

标题

位于emt文件开头,格式如下:

title{标题}*

大括号中的内容会自动赋值给doc_title变量,最后渲染到page.emt中的对应位置

末尾的*表示注释,用来防止在渲染HTML时输出title标签,不能省略

无标题(或标题为空)的emt文件会被当作模板处理(无法通过浏览器直接访问)

引入CSS

在需要引入的位置加上

scr[t=module]{import 'example.styl'}

vite会自动将生成的css插入到head中

emmet语法扩展

input:

.flex.items-center
	p 6
	max-w sm
	mx auto
	shadow lg
	space x 4

output:

<div class="flex items-center p-6 max-w-sm mx-auto shadow-lg space-x-4"></div>

cssProps中的属性当成内联样式处理

input:

#s
	p 0
	width 50%

output:

<div id="s" class="p-0" style="width:50%"></div>

若标签名末尾带有冒号,则将该部分当CSS而非HTML处理

若属性名末尾带有冒号,则生成 CSS选择器生成规则:从距离最近的带有id的父元素或根元素开始直到本元素,以>连接

input:

#t
	dl
		dt:after
			content: ":"
		dd
			margin: 0

output: HTML

<div id="t"><dl><dt></dt><dd></dd></dl></div>

CSS

#t>dl>dt:after{content:":"}
#t>dl>dd{margin:0}

预处理器

Stylus预处理器

inlineStylus:将所有Shadow DOM内的style标签的内容视为stylus处理,再将生成的css交给unocss处理

使用:

import { inlineStylus } from 'vite-plugin-emt'

export default defineConfig({
	// …
	plugins: [
		inlineStylus(),
		// …
	],
})

TypeScript预处理器

inlineTS:将所有内联<script>当成TypeScript处理

使用:

import { inlineTS } from 'vite-plugin-emt'

export default defineConfig({
	// …
	plugins: [
		inlineTS(),
		// …
	],
})

预处理器类型声明

在env.d.ts中加上

import { Preprocessor } from 'vite-plugin-emt'

declare global {
	declare const emt: Preprocessor, styl: Preprocessor
}

若指定了Options.literal,上面代码中的emt和styl需要改为Options.literal指定的名称