-
Notifications
You must be signed in to change notification settings - Fork 6
/
config-overrides.js
109 lines (77 loc) · 2.37 KB
/
config-overrides.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
const
Path = require('path'),
PostBuild = require('./PostBuild'),
TSCompilerPlugin = require('webpack-rollup-ts-compiler'),
FontPreloadPlugin = require('webpack-font-preload-plugin'),
MinimalClassnameGenerator = require('webpack-minimal-classnames'),
{ override, removeModuleScopePlugin, babelInclude } = require('customize-cra');
let DIST_DIR = '';
const isProduction = process.env.NODE_ENV === "production";
const generateMinimalClassname = MinimalClassnameGenerator({
length: 1,
excludePatterns: [/ad/i]
})
let settings = {};
module.exports = {
paths: (paths) => {
DIST_DIR = paths.appBuild;
},
webpack: override((config) => {
if (isProduction) {
JSON.stringify(config, (_key, value) => {
if (typeof value === 'object' && value && typeof value.loader === 'string' &&
value.loader.includes('css-loader') && value.options && value.options.modules) {
value.options.modules.getLocalIdent = generateMinimalClassname;
}
return value;
})
}
config = removeModuleScopePlugin()(config);
config = babelInclude()(config);
if (isProduction) {
delete config.devtool;
}
config.plugins = config.plugins.map((plugin) => {
if (isProduction && plugin.constructor.name === 'WebpackManifestPlugin') {
return undefined;
}
if (0);
else if (plugin.constructor.name === "HtmlWebpackPlugin") {
plugin = new plugin.constructor({
...plugin.userOptions,
cache: false,
templateParameters: () => ({ settings }),
isProduction,
});
}
else if (plugin.constructor.name === "DefinePlugin") {
plugin = new plugin.constructor({
...plugin.definitions,
isProduction
});
}
return plugin;
})
config.plugins.push(new TSCompilerPlugin(
Path.resolve(__dirname, '../shared/Settings.ts'), {
postprocess: (result) => {
settings = new Function(`return ${result}`)()
return {}
}
}
))
config.plugins.push(new TSCompilerPlugin(Path.resolve(__dirname, 'src/serviceWorker.ts'), {
to: 'sw.js',
}))
config.plugins.push(new TSCompilerPlugin(Path.resolve(__dirname, 'src/manifest.ts'), {
to: 'manifest.json',
postprocess: (manifest) => JSON.stringify(new Function(`return ${manifest}`)(), null, '\t') },
));
if (isProduction) {
config.plugins.push(new PostBuild(DIST_DIR));
} else {
config.plugins.push(new FontPreloadPlugin());
}
return config;
})
};