forked from cagov/unemployment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
postcss.config.js
54 lines (49 loc) · 1.64 KB
/
postcss.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* @file PostCSS configuration file, used for defining how our CSS files are compiled.
* @see https://github.com/postcss/postcss
* @see https://github.com/postcss/postcss-cli
*/
const autoprefixer = require("autoprefixer");
const cssnano = require("cssnano");
const hash = require("postcss-hash");
const path = require("path");
const sass = require("@csstools/postcss-sass");
// Path to file where the generated CSS filenames will be stored for reference by our server
const manifestPath = "./src/data/manifest-styles.json";
const sassOptions = {
includePaths: ["./src/client", "./node_modules"],
sourceMap: true,
};
const sourceMapOptions = { annotation: true, inline: false };
module.exports = (context) => {
const isDevelopment = context.env === "development";
return {
map: sourceMapOptions,
parser: "postcss-scss",
plugins: [
// Compile Sass to CSS
sass(sassOptions),
// Add browser prefixes to newer CSS properties
autoprefixer,
// Minify the .css file
cssnano({
preset: ["default", { discardComments: { removeAll: true } }],
}),
// Append cache-buster hash to filename and create the manifest file
hash({
manifest: manifestPath,
name: generateHashedFilename(isDevelopment),
}),
],
};
};
function generateHashedFilename(isDevelopment) {
return function ({ dir, name, hash, ext }) {
if (isDevelopment) {
// During development, we don't want to generate a new file
// every time the CSS changes since that prevents live reloading
return path.join(dir, name + ext);
}
return path.join(dir, name + "." + hash + ext);
};
}