# postcss-query-hash

> Output a manifest file for cache busting.

Latest version **1.0.0** (published 2019-02-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install postcss-query-hash
pnpm add postcss-query-hash
yarn add postcss-query-hash
bun add postcss-query-hash
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2019-02-17 |
| First published | 2019-02-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 5.6 KB |
| Known vulnerabilities | 0 (+5 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | highhi |
| Maintainers | highhi |
| Keywords | postcss, css, postcss-plugin, postcss-query-hash, cache-busting, cache-buster, hash, md5, md4, md2, sha, sha1, sha224, sha256, sha384, sha512, mdc2, manifest |

## Links

- npm: https://www.npmjs.com/package/postcss-query-hash
- Repository: https://github.com/highhi/postcss-query-hash
- Issues: https://github.com/highhi/postcss-query-hash/issues
- npm.io page: https://npm.io/package/postcss-query-hash

## Dependencies (2)

- [mkdirp](https://npm.io/package/mkdirp.md) ^0.5.1
- [postcss](https://npm.io/package/postcss.md) ^7.0.14

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2019-02-17

## README

# postcss-query-hash
Output a manifest file for cache busting.

## Usage

CLI
```
# input 
postcss ./src/**/*.css -d /dist

# output manifest.json
{
  "/dist/style.css":"/dist/style.css?a516675ef8",
  "/dist/user/user.css":"/dist/user/user.css?gh9848whf"
}
```
Node script

```javascript
# input

const postcss = require('postcss')
const fs = require('fs')
const queryHash = require('postcss-query-hash')
const glob = require('glob')
const { promisify } = require('util')
const readFile = promisify(fs.readFile)

const CWD = __dirname
const SRC = `${CWD}/src`
const DIST = `${CWD}/dist`
const MANIFEST = `${DIST}/manifest.json`
const files = glob.sync(`${SRC}/**/*.css`)

try {
  fs.unlinkSync(MANIFEST)
} catch (_) {}

files.forEach(async file => {
  const css = await readFile(file)

  try {
    await postcss([queryHash({ manifest: MANIFEST })]).process(css, {
      from: file,
      to: file.replace(SRC, DIST),
      cwd: CWD,
    })
  } catch (err) {
    console.error(err)
  }
})

# output manifest.json
{
  "/dist/style.css":"/dist/style.css?a516675ef8",
  "/dist/user/user.css":"/dist/user/user.css?gh9848whf"
}
```

## Options
### algorithm
Type: `String`  
Default: `md5`  

Uses node's inbuilt crypto module. Pass any digest algorithm that is supported in your environment.

### manifest
Type: `String`  
Default: `./manifest.json`

Output destination of the manifest file.

## license
MIT

---
_Source: https://npm.io/package/postcss-query-hash · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
