This repository is a modular TypeScript HTML minifier built on PostHTML. Follow the notes below to run builds/tests and match the existing style.
src/core TypeScript sourcessrc/_modules/individual minifier modulessrc/presets/preset definitionssrc/bin/CLI entrytest/mocha tests and fixturesdocs/Docusaurus sitedist/build output (generated)
npm install
npm run build:
- Runs
rimraf distthenbunchee, thenchmod +x dist/bin.js. npm run compileis an alias fornpm run build.
npm run lint:
- Uses
eslint --fix .(auto-fixes where possible).
npm test:
pretestruns lint + compile.testruns mocha with SWC/TypeScript:mocha --timeout 5000 --require @swc-node/register --recursive --check-leaks --globals addresses 'test/**/*.ts'.
Use mocha directly so you can target a file or grep a test name.
npm run build && npx mocha --timeout 5000 --require @swc-node/register --recursive --check-leaks --globals addresses "test/modules/minifyCss.ts"
It's IMPORTANT to run npm run build first, because the tests use the code from dist/.
If you don't do that, you'll be testing outdated code.
You can only omit npm run build if you haven't changed the main code, only the tests.
npm run build
npm run start
- Rely on eslint doing formatting.
- Tabs are allowed in
test/**/*(fixtures), otherwise avoid tabs.
- Use ESM syntax everywhere.
- Use
import typefor type-only imports; keep type imports at the top-level when possible (import-x/consistent-type-specifier-style: prefer-top-level). - Avoid unused imports;
_-prefixed args/vars are allowed but should be rare. - For local relative imports in TS, follow existing
.jsextension usage (required for ESM output).
camelCasefor variables/properties (ESLintcamelcaseenforced).- Use clear, descriptive module names that match preset keys.
- File names are lowercase with optional dashes or camel case.
- Use named function instead of constants (e.g.,
function foob() { }instead ofconst foob = () => {}).
strictandstrictNullChecksare enabled.noUnusedLocalsandnoImplicitReturnsare enabled.- Target
es2018, modulePreserve, resolutionBundler. .d.tsfiles allow unused vars and duplicate imports.- Prefer explicit types for public exports and module interfaces.
- Throw
Error/TypeErrorfor invalid states (seesrc/index.ts). @typescript-eslint/only-throw-erroris enabled but allows rethrowing.- When optional dependencies are missing, warn and continue if the option
skipInternalWarningsis set totrue.
- Unused imports are errors (
unused-imports/no-unused-imports). @typescript-eslint/no-explicit-anyis a warning (avoid unless needed).- Exhaustive switch checks enforced.
- Namespace usage is allowed (
@typescript-eslint/no-namespace: off).
- Modules live in
src/_modules/and export a defaultHtmlnanoModule. - Presets live in
src/presets/and list enabled module keys. - Add tests in
test/modules/for new modules. - Update docs for new modules or preset changes.
- Each module should handle only its own related minifications. For example,
mergeScriptsshouldn't care about white spaces between<script>tags as they'll be handled bycollapseWhitespaces.