onehtml
v0.1.0
Published
Inline your HTML assets (styles, scripts, images) into a single self-contained file. Works both as a **CLI** and as a **library**.
Readme
onehtml
Inline your HTML assets (styles, scripts, images) into a single self-contained file. Works both as a CLI and as a library.
📦 Install
As a library:
npm install onehtmlAs a CLI (without install):
npx onehtml🚀 Usage
CLI
onehtml reads HTML from stdin and writes the processed output to stdout or to a file if OUTPUT is set.
Example:
cat index.html | npx onehtml > bundled.htmlor with an output file:
cat index.html | OUTPUT=dist.html npx onehtmlEnvironment variables
| Variable | Type | Default | Description |
|-------------------|--------|---------------|----------------------------------------------|
| INLINE_STYLES | bool | true | Inline <link rel="stylesheet"> |
| INLINE_SCRIPTS | bool | true | Inline <script src="..."> |
| INLINE_IMAGES | bool | true | Inline <img src="..."> as data URIs |
| MAX_CONCURRENCY | number | 10 | Max parallel downloads |
| CACHE_DIR | path | /tmp/onehtml| Cache directory for fetched assets |
| ROOT_DIR | path | cwd | Root directory for resolving local files |
| OUTPUT | path | stdout | File to write output to |
Library
import onehtml from 'onehtml';
import fs from 'fs';
const inliner = onehtml({
inlineStyles: true,
inlineScripts: true,
inlineImages: true,
maxConcurrency: 10,
cacheDir: '/tmp/onehtml',
rootDir: process.cwd()
});
await inliner
.from(fs.createReadStream('index.html'))
.to(fs.createWriteStream('bundled.html'))
;✨ Example
INLINE_IMAGES=false OUTPUT=out.html npx onehtml < index.htmlThis disables image inlining and writes the result to out.html.
📄 License
ISC
