Skip to content

Commit

Permalink
publish inputs.css; fix namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Jul 26, 2024
1 parent 88b34c7 commit 29d1af2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
15 changes: 15 additions & 0 deletions bin/clean-css.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {stdin} from "node:process";
import CleanCSS from "clean-css";

stdin.setEncoding("utf-8");

let input = "";

for await (const chunk of stdin) {
input += chunk;
}

// A unique namespace for our styles.
const styleNs = "oi-3a86ea";

process.stdout.write(new CleanCSS().minify(input.replace(/\.__ns__\b/g, `.${styleNs}`)).styles);
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@
"jsdelivr": "dist/inputs.min.js",
"unpkg": "dist/inputs.min.js",
"exports": {
"umd": "./dist/inputs.min.js",
"default": "./src/index.js"
".": {
"umd": "./dist/inputs.min.js",
"default": "./src/index.js"
},
"./dist/inputs.css": "./dist/inputs.css"
},
"repository": {
"type": "git",
"url": "https://github.com/observablehq/inputs.git"
},
"files": [
"dist/**/*.css",
"dist/**/*.js",
"src/**/*.js"
],
Expand All @@ -31,7 +35,7 @@
"test": "yarn test:mocha && yarn test:lint",
"test:mocha": "mkdir -p test/output && mocha -r module-alias/register 'test/**/*-test.js' test/input.js",
"test:lint": "eslint src test",
"prepublishOnly": "rm -rf dist && rollup -c",
"prepublishOnly": "rm -rf dist && rollup -c && node bin/clean-css < src/style.css > dist/inputs.css",
"postpublish": "git push && git push --tags",
"dev": "snowpack dev"
},
Expand Down
7 changes: 3 additions & 4 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import crypto from "crypto";
import fs from "fs";
import path from "path";
import {terser} from "rollup-plugin-terser";
Expand All @@ -22,10 +21,10 @@ const copyrights = fs.readFileSync("./LICENSE", "utf-8")
.filter(line => /^copyright\s+/i.test(line))
.map(line => line.replace(/^copyright\s+/i, ""));

// Create a content-hashed namespace for our styles.
// A unique namespace for our styles.
const styleNs = "oi-3a86ea";

const stylePath = path.resolve("./src/style.css");
const styleHash = crypto.createHash("sha256").update(fs.readFileSync(stylePath, "utf8")).digest("hex").slice(0, 6);
const styleNs = `oi-${styleHash}`;

// A lil’ Rollup plugin to allow importing of style.css.
const css = {
Expand Down

0 comments on commit 29d1af2

Please sign in to comment.