strip-wc-comments
v0.1.1
Published
Strip JSDoc, inline, and HTML comments from distributed web component JS files
Downloads
317
Maintainers
Readme
strip-wc-comments
Strip JSDoc, inline, and HTML comments from distributed web component JS files.
Web component libraries ship JS files that include JSDoc blocks, inline comments, and HTML comments inside template literals for slot documentation. These are useful during development but unnecessary in production. This tool removes them.
Install
npm install strip-wc-commentsUsage
npx strip-wc-comments [options] <file-or-dir> [...]With no flags, all comment types are stripped.
npx strip-wc-comments ./node_modules/@my-lib/elements/Strip only specific comment types:
npx strip-wc-comments --jsdoc --html ./node_modules/@my-lib/elements/Preview changes without writing:
npx strip-wc-comments --dry-run ./node_modules/@my-lib/elements/Write to a separate directory instead of modifying in place:
npx strip-wc-comments -o dist-clean/ ./node_modules/@my-lib/elements/Options
| Flag | Description |
| --- | --- |
| -j, --jsdoc | Strip JSDoc comments (/** ... */) |
| -i, --inline | Strip single-line comments (// ...) |
| -H, --html | Strip HTML comments inside template literals (<!-- ... -->) |
| -s, --sourcemap | Strip //# sourceMappingURL lines |
| -a, --all | Strip all comment types (default if no flags given) |
| -n, --dry-run | Print what would change without writing files |
| -o, --out <dir> | Write cleaned files to <dir> instead of modifying in place |
| -h, --help | Show help |
Comment types
JSDoc (--jsdoc) — class-level descriptions, @summary, @alias, property and method docs:
/**
* Provides a styled link or button for prominent user actions.
* @summary Styled link or button for prominent user actions
*/Inline (--inline) — TODO notes, workaround comments, eslint directives:
// workaround for lit-ssr bugs
// TODO: remove in next major versionHTML (--html) — slot documentation embedded in tagged template literals:
html`<!--
summary: Default slot
description: |
Slot an anchor or button as the first child.
--><slot></slot>`;Source maps (--sourcemap) — trailing source map references:
//# sourceMappingURL=my-element.js.mapSSR + CDN hydration
[!WARNING] If you server-side render web components from local files and hydrate on the client from a CDN, the sources must match. Stripping comments from only your local copy creates a mismatch between the server-rendered declarative shadow DOM and the client-side component definitions. This can cause hydration errors, duplicated shadow roots, or broken interactivity.
Either strip comments from both sources or neither. If you only control the local files, do not strip comments unless the CDN serves the same modified build.
CI/CD
Run as an explicit build step in your pipeline:
strip-wc-comments -o dist/ ./node_modules/@my-lib/elements/