-
Notifications
You must be signed in to change notification settings - Fork 1
/
craco.config.js
56 lines (52 loc) · 1.94 KB
/
craco.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
const path = require('path');
const webpack = require('webpack');
// https://gist.github.com/vimcaw/2056dbc92ec7a8cc8fdcec0c513ed45c
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
webpack: {
alias: {
// ts-utils uses the `exports` package.json options, which is not supported in webpack 4
// this can be removed if we update react-scripts
'@openstax/ts-utils': '@openstax/ts-utils/dist/cjs'
},
},
plugins: [{
plugin: {
// Based on https://github.com/kevinsperrine/craco-workbox/blob/master/lib/index.js
overrideWebpackConfig: ({ webpackConfig, context: { env, paths } }) => {
if (env === "production") {
try {
const workboxConfig = require(path.join(
paths.appPath,
"workbox.config.js"
));
webpackConfig.plugins.forEach(plugin => {
if (plugin.constructor.name === "InjectManifest") {
plugin.config = workboxConfig(plugin.config);
}
});
} catch (error) {
console.log("[craco.config.js - overrideWebpackConfig]");
console.log(error.stack);
process.exit(1);
}
}
const htmlWebpackPluginInstance = webpackConfig.plugins.find(
webpackPlugin => webpackPlugin instanceof HtmlWebpackPlugin
);
if (htmlWebpackPluginInstance) {
htmlWebpackPluginInstance.options.scriptLoading = 'defer';
}
return webpackConfig;
}
},
}],
style: {
css: {
loaderOptions: {
// https://github.com/openstax/unified/issues/1469
url: false,
},
},
},
};