-
Notifications
You must be signed in to change notification settings - Fork 4
/
config-overrides.js
66 lines (59 loc) · 2.44 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
const fs = require("fs-extra");
const path = require("path");
const RewireReactHotLoader = require("react-app-rewire-hot-loader");
const WriteFilePlugin = require("write-file-webpack-plugin");
const WEBPACK_DEV_SERVER_URL = `http://localhost:${process.env.PORT || 3000}`;
// Make sure any symlinks in the project folder are resolved:
// https://github.com/facebook/create-react-app/issues/637
const appDirectory = fs.realpathSync(process.cwd());
const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
const paths = {
appBuild: resolveApp("build"),
appPublic: resolveApp("public")
};
module.exports = function override(config, webpackEnv) {
const isEnvDevelopment = webpackEnv === "development";
if (isEnvDevelopment) {
// Replace `react-dev-utils/webpackHotDevClient` with stock client due to an
// unresolved issue that's preventing web extensions from connecting to the
// dev server. (https://github.com/facebook/create-react-app/issues/4468)
if (config.entry[0].includes("react-dev-utils/webpackHotDevClient")) {
const __resourceQuery = `?${WEBPACK_DEV_SERVER_URL}`;
config = RewireReactHotLoader(config, webpackEnv);
// Use resource query to configure `webpack-dev-server/client` to use the
// our URL when establishing the socket connection to the dev server.
config.entry.splice(
0,
1,
require.resolve("webpack-dev-server/client") + __resourceQuery,
require.resolve("webpack/hot/dev-server") + __resourceQuery
);
// Use `react-hot-loader`'s version of `react-dom`
config.resolve.alias = {
...config.resolve.alias,
"react-dom": "@hot-loader/react-dom"
};
}
// Write webpackDevServer output to disk to allow the application to be
// installed temporary on browsers.
// See https://www.rubberduck.io/blog/browser-extensions-react
config.output.path = paths.appBuild;
config.output.futureEmitAssets = false;
config.plugins.push(new WriteFilePlugin());
fs.removeSync(paths.appBuild);
fs.copySync(paths.appPublic, paths.appBuild, {
filter: src => {
const filename = path.basename(src);
if (filename.match(/manifest(\.[a-z]+)?.json/)) {
return filename === "manifest.development.json";
}
return true;
}
});
fs.renameSync(
`${paths.appBuild}/manifest.development.json`,
`${paths.appBuild}/manifest.json`
);
}
return config;
};