Coding
PromptBeginner5 minmarkdown
Markdown Converter
Agent skill for markdown-converter
7
This file provides guidance to Agents when working with code in this repository.
Sign in to like and favorite skills
This file provides guidance to Agents when working with code in this repository.
unplugin-use-minify is an unplugin that enables selective, function-level minification using the "use minify" directive. It uses OXC (Oxidation Compiler) for parsing and minification, applying transformations only to functions that explicitly opt-in.
# Build the project (using tsdown) pnpm run build # Run tests (using vitest) pnpm run test # Run linter (ESLint) pnpm run lint # Format code (Biome) pnpm run format # Type checking pnpm run typecheck # Publish preview with pkg-pr-new pnpm run pkg-pr-new
src/core/index.ts)The main transformation pipeline:
oxc-parser to parse source code into AST with TypeScript/TSX supportFunctionDeclaration, ArrowFunctionExpression, and FunctionExpression nodesshouldMinifyThisBlock() to check if function has BlockStatement body containing "use minify" as the first statementminifyFunction() with oxc-minify to matching functionsMagicString to apply replacements after removing contained/nested replacements via removeContained() to handle nested functions correctlysrc/index.ts)unplugin to create unified plugin interfaceunplugin-utilsenforce timing (pre/post)[/\.[cm]?[jt]sx?$/][/node_modules/]Each file (
vite.ts, webpack.ts, rspack.ts, rollup.ts, rolldown.ts, esbuild.ts, farm.ts) exports the plugin configured for that specific bundler.
function foo() { "use minify"; ... }const foo = function() { "use minify"; ... }const foo = () => { "use minify"; ... }"use minify" are processed independently (handled by removeContained())const foo = () => x * 2 (no BlockStatement)src/core/index.ts for UserMinifyOptions type definition and detailed commentssrc/core/options.ts for plugin optionscompress option is currently disabled due to OXC bug (see comments in src/core/index.ts)Tests use
@sxzz/test-utils for fixture-based snapshot testing. See tests/fixtures/basic.ts for comprehensive examples of supported and unsupported cases.