-
Notifications
You must be signed in to change notification settings - Fork 9
/
config-overrides.js
146 lines (137 loc) · 4.38 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
const path = require("path");
const { override } = require("customize-cra");
const { addReactRefresh } = require("customize-cra-react-refresh");
const { GenerateSW } = require("workbox-webpack-plugin");
const ManifestPlugin = require("webpack-manifest-plugin");
const DynamicCdnWebpackPlugin = require("dynamic-cdn-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin");
const WriteJsonPlugin = require("write-json-webpack-plugin");
const { LicenseWebpackPlugin } = require("license-webpack-plugin");
const EventHooksPlugin = require("event-hooks-webpack-plugin");
const webpack = require("webpack");
const merge = require("webpack-merge");
const createConfig = require("./scripts/createConfig");
const renderLicenses = require("./scripts/renderLicenses");
const downloadLicenses = require("./scripts/downloadLicenses");
const fixUrlPathEncoding = require("./scripts/fixUrlPathEncoding");
const buildSubDir = "viewer";
// Download license files for modules that haven't included them in their npm package
downloadLicenses([
{
module: "draco3d",
url:
"https://raw.githubusercontent.com/google/draco/8a979f79a5f139880f17f296ace90bcfff025c4b/LICENSE",
},
{
module: "file-selector",
url:
"https://raw.githubusercontent.com/react-dropzone/file-selector/d2b44e213c0ca5cedbe01b1aabc06814e4bb91dc/LICENSE",
},
{
module: "isarray",
url:
"https://raw.githubusercontent.com/juliangruber/isarray/29a4977d09cfab83886cbb97d1710a01d0358e52/LICENSE",
},
{
module: "is-in-browser",
url:
"https://raw.githubusercontent.com/tuxsudo/is-in-browser/56378377a3767c5822313a6aac846e9b10abb6ed/LICENSE",
},
{
module: "popper.js",
url:
"https://raw.githubusercontent.com/popperjs/popper-core/70edad694ed244851a515ca2cfd8397c4ddb867f/LICENSE.md",
},
]);
module.exports = {
jest: config => {
config.testEnvironment = "jest-environment-jsdom-sixteen";
config.testEnvironmentOptions = { resources: "usable" };
return config;
},
webpack: override(config => {
config = addReactRefresh({ disableRefreshCheck: true })(config);
// Disable some default plugins
config.plugins = config.plugins.filter(
plugin =>
![GenerateSW, ManifestPlugin].some(
disabledPlugin => plugin instanceof disabledPlugin,
),
);
// Place static assets in sub dir
config.module.rules
.find(rule => rule.oneOf)
.oneOf.filter(
rule =>
rule.options &&
rule.options.name &&
rule.options.name.includes("static"),
)
.forEach(
loader =>
(loader.options.name = path.join(buildSubDir, loader.options.name)),
);
// Don't extract license comments (will use separate license plugin)
config.optimization.minimizer = [
new TerserPlugin({
terserOptions: {
format: {
comments: false,
},
},
extractComments: false,
}),
];
const plugins = [
new webpack.DefinePlugin({
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV),
}),
new DynamicCdnWebpackPlugin(),
new WriteJsonPlugin({
object: createConfig(true),
path: "",
filename: "index.json",
pretty: true,
}),
new WriteJsonPlugin({
object: createConfig(false),
path: "",
filename: "index-release.json",
pretty: true,
}),
new LicenseWebpackPlugin({
outputFilename: "viewer/static/js/licenses.txt",
additionalModules: Object.keys(
require("./package.json").dependencies,
).map(dependency => {
return {
name: dependency,
directory: path.join(__dirname, "node_modules", dependency),
};
}),
renderLicenses: renderLicenses,
perChunkOutput: false,
stats: {
warnings: true,
errors: true,
},
}),
];
if (config.mode === "production") {
plugins.push(
new EventHooksPlugin({
done: () =>
fixUrlPathEncoding(path.join(config.output.path, "index.html")),
}),
);
}
return merge(config, {
plugins: plugins,
output: {
// Place js output in sub dir
filename: path.join(buildSubDir, config.output.filename),
chunkFilename: path.join(buildSubDir, config.output.chunkFilename),
},
});
}),
};