-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcraco.config.js
More file actions
73 lines (68 loc) · 2.95 KB
/
Copy pathcraco.config.js
File metadata and controls
73 lines (68 loc) · 2.95 KB
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
64
65
66
67
68
69
70
71
72
73
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';
}
// dompurify 3.4.11 ships purify.js.map with null sourcesContent. babel chains
// it into the bundle sourcemap via normalize-file.js line 67's inputSourceMap
// check. Setting sourceMaps: false makes babel return [code, null], so webpack
// uses OriginalSource (no TS entries) rather than SourceMapSource.
const oneOfRules = webpackConfig.module.rules.find(rule => rule.oneOf).oneOf;
const depsRuleIdx = oneOfRules.findIndex(
rule => rule.loader && rule.loader.includes('babel-loader') && !rule.include
);
if (depsRuleIdx >= 0) {
const depsRule = oneOfRules[depsRuleIdx];
oneOfRules.splice(depsRuleIdx, 0, {
test: /node_modules[\\/]dompurify[\\/]/,
loader: depsRule.loader,
options: Object.assign({}, depsRule.options, { sourceMaps: false }),
});
}
return webpackConfig;
}
},
}],
style: {
css: {
loaderOptions: {
// https://github.com/openstax/unified/issues/1469
url: false,
},
},
},
};