-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcritical.config.js
63 lines (60 loc) · 2.02 KB
/
critical.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
55
56
57
58
59
60
61
62
63
// critical.config.js
// returns a webpack config object for generating critical css
// webpack plugins
const CriticalCssPlugin = require('critical-css-webpack-plugin');
// return a webpack config
module.exports = (type = 'modern', settings) => {
const criticalCssPlugins = () => {
return (settings.critical.pages.map((row) => {
const criticalSrc = settings.urls.criticalCss + row.uri;
const criticalDest = settings.critical.base + row.template + settings.critical.suffix;
let criticalWidth = settings.critical.criticalWidth;
let criticalHeight = settings.critical.criticalHeight;
// Handle Google AMP templates
if (row.template.indexOf(settings.critical.ampPrefix) !== -1) {
criticalWidth = settings.critical.ampCriticalWidth;
criticalHeight = settings.critical.ampCriticalHeight;
}
return new CriticalCssPlugin({
base: './',
src: criticalSrc,
target: criticalDest,
extract: false,
inline: false,
minify: true,
width: criticalWidth,
height: criticalHeight,
})
})
);
};
// common config
const common = () => ({
plugins: criticalCssPlugins(),
});
// configs
const configs = {
// development configs
development: {
// legacy development config
legacy: {
},
// modern development config
modern: {
...common(),
},
},
// production configs
production: {
// legacy production config
legacy: {
...common(),
},
// modern production config
modern: {
...common(),
},
}
};
return configs[process.env.NODE_ENV][type];
}