Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

postcss-query-hash

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-query-hash

Output a manifest file for cache busting.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

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

# 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

Keywords

FAQs

Package last updated on 17 Feb 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc