https://github.com/tylors/typed-content-hash
Rewrite your HTML/JS/CSS (and sourceMap!) files with SHA-512 content hashes
https://github.com/tylors/typed-content-hash
assets cli content-hash hashing sha512 sourcemaps static-files
Last synced: 15 days ago
JSON representation
Rewrite your HTML/JS/CSS (and sourceMap!) files with SHA-512 content hashes
- Host: GitHub
- URL: https://github.com/tylors/typed-content-hash
- Owner: TylorS
- Created: 2021-01-04T02:10:35.000Z (almost 5 years ago)
- Default Branch: development
- Last Pushed: 2023-03-05T18:42:18.000Z (over 2 years ago)
- Last Synced: 2024-12-28T19:12:54.897Z (9 months ago)
- Topics: assets, cli, content-hash, hashing, sha512, sourcemaps, static-files
- Language: TypeScript
- Homepage:
- Size: 755 KB
- Stars: 12
- Watchers: 3
- Forks: 3
- Open Issues: 8
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# @typed/content-hash
Rewrite a directory of static files with SHA-512 content hashes, with first-class support for source maps, and generate an asset manifest reflecting the filename changes.
## Features
- SHA-512 Content Hashes, with configurable length.
- Deterministic, content-based hashes.
- Supports circular dependencies!
- [TypeScript API](#API), with a simple plugin API.
- Generates an Asset Manifest as JSON
- Simple CLI
- [Generates](https://github.com/Rich-Harris/magic-string) and [remaps](https://github.com/ampproject/remapping) SourceMaps## CLI
```sh
$ typed-content-hash --dir buildOptions:
--version Show version number [boolean]
--directory, --dir The directory to apply content hashes
[string] [required]
--assetManifest Filename of asset manifest JSON
[string] [default: "asset-manifest.json"]
-h, --hashLength Number of characters to slice from SHA-512 hash
[number]
--tsConfig Relative path to tsconfig from CWD
[string] [default: "tsconfig.json"]
--baseUrl Base URL to use when rewriting imports/exports[string]
--logLevel [string] [choices: "debug", "info", "error"] [default: "info"]
--registryFile Configure where to write Document Registry to JSON.
Useful for debugging [string]
--sourceMaps [boolean] [default: true]
--mainFields Configure package.json fields to look for dependencies
[array] [default: ["module"]]
--help Show help [boolean]
```## API
For the moment `contentHashDirectory` is the main API function you'd be interested in using. The CLI is a small wrapper around running just this function.
There is a plugin API available to expand support to additional file extensions besides the default supported files. If you're interested in this take a look at `src/content-hashes/infrastructure/plugins` for examples of
the default plugins.### contentHashDirectory :: ContentHashOptions -> Promise DocumentRegistry
#### Basic Example
```typescript
import { contentHashDirectory, createDefaultPlugins } from '@typed/content-hash'
import { join } from 'path'async function main() {
const registry: DocumentRegistry = await contentHashDirectory({
directory: '/path/to/directory',
plugins: createDefaultPlugins({ buildDirectory: '/path/to/directory' })
})
}main()
```## Discussions
We've enabled [Github Discussions](https://github.com/TylorS/typed-content-hash/discussions) if you would ever like to reach out about anything related to the project!
## Related Projects
- [snowpack-plugin-hash](https://github.com/TylorS/snowpack-plugin-hash) - Uses library