0.10.1 • Published 2 years ago

@typed/content-hash v0.10.1

Weekly downloads
249
License
MIT
Repository
github
Last release
2 years ago

@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, with a simple plugin API.
  • Generates an Asset Manifest as JSON
  • Simple CLI
  • Generates and remaps SourceMaps

CLI

$ typed-content-hash --dir build

Options:
      --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

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 if you would ever like to reach out about anything related to the project!

Related Projects

0.10.1

2 years ago

0.10.0

3 years ago

0.9.0

3 years ago

0.8.3

3 years ago

0.8.2

3 years ago

0.8.1

3 years ago

0.8.0

3 years ago

0.7.0

3 years ago

0.6.3

3 years ago

0.6.2

3 years ago

0.6.1

3 years ago

0.6.0

3 years ago

0.5.0

3 years ago

0.4.0

3 years ago

0.3.6

3 years ago

0.3.5

3 years ago

0.3.4

3 years ago

0.3.3

3 years ago

0.3.2

3 years ago

0.3.0

3 years ago

0.2.0

3 years ago

0.3.1

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago