Skip to content

Commit 29147e1

Browse files
committed
Generate computed and non-computed assets
The computed asset, 98.css, precomputes the values that uses CSS variables. The non-computed asset, 98-full.css, preserves the variables and uses the computed values as fallbacks for browsers without support for custom properties.
1 parent fa6f527 commit 29147e1

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

build.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,27 @@ const postcss = require("postcss");
1010

1111
const { homepage, version } = require("./package.json");
1212

13-
function buildCSS() {
13+
function buildCSS(preserveVariables) {
1414
const input =
1515
`/*! 98.css v${version} - ${homepage} */\n` + fs.readFileSync("style.css");
16+
const destination = preserveVariables ? "dist/98-full.css" : "dist/98.css";
17+
const template = preserveVariables ? "[name]-full.[ext]" : "[name].[ext]";
1618

1719
return postcss()
1820
.use(require("postcss-inline-svg"))
19-
.use(require("postcss-css-variables"))
21+
.use(require("postcss-css-variables")({ preserve: preserveVariables }))
2022
.use(require("postcss-calc"))
21-
.use(require("postcss-copy")({ dest: "dist", template: "[name].[ext]" }))
23+
.use(require("postcss-copy")({ dest: "dist", template }))
2224
.use(require("cssnano"))
2325
.process(input, {
2426
from: "style.css",
25-
to: "dist/98.css",
27+
to: destination,
2628
map: { inline: false },
2729
})
2830
.then((result) => {
2931
mkdirp.sync("dist");
30-
fs.writeFileSync("dist/98.css", result.css);
31-
fs.writeFileSync("dist/98.css.map", result.map.toString());
32+
fs.writeFileSync(destination, result.css);
33+
fs.writeFileSync(destination + ".map", result.map.toString());
3234
});
3335
}
3436

@@ -72,7 +74,8 @@ function buildDocs() {
7274
}
7375

7476
function build() {
75-
buildCSS()
77+
buildCSS(false)
78+
.then(() => buildCSS(true))
7679
.then(buildDocs)
7780
.catch((err) => console.log(err));
7881
}

0 commit comments

Comments
 (0)