This repository has been archived by the owner on Sep 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 249
/
WebpackServerConfigModifier.js
73 lines (66 loc) · 2.15 KB
/
WebpackServerConfigModifier.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
import webpack from "webpack";
import getWebpackConfig from "./WebpackGetConfig.js";
const requireSourceMapSupport = `require('${require
.resolve("source-map-support/register")
// windows support
.replace(/\\/g, "/")}');`;
const defaultExternals = [
// we could consider node_modules as externals deps
// and so use something like
// /^[A-Za-z0-9-_]/
// to not bundle all deps in the static build (for perf)
// the problem is that if people rely on node_modules for stuff
// like css, this breaks their build.
//
// @todo find a better way than a whitelist
// to support react hooks, we need to be sure that static rendering
// use only one react
// https://github.com/facebook/react/issues/13991
"react",
"react-dom",
// https://github.com/websockets/ws/issues/1220
"bufferutil",
"utf-8-validate",
/^apollo(\/.*)?/,
/^aphrodite(\/.*)?/,
/^emotion(\/.*)?/,
/^glamor(\/.*)?/,
/^react-native(-web)?(\/.*)?/, // "react-native-web" can be used as an alias or "react-native"
/^react-helmet(\/.*)?/,
];
export default (config, cacheDir) => {
const webpackConfig = getWebpackConfig(config);
return {
...webpackConfig,
// only keep the entry we are going to use
entry: {
[config.bundleName]: webpackConfig.entry[config.bundleName],
},
// adjust some config details to be node focused
target: "node",
// externals for package/relative name
externals: [...(webpackConfig.externals || defaultExternals)],
output: {
publicPath: config.baseUrl.pathname,
path: cacheDir,
filename: "[name].js",
library: "app",
libraryTarget: "commonjs2",
devtoolModuleFilenameTemplate: "[absolute-resource-path]",
},
plugins: [
...webpackConfig.plugins,
// sourcemaps
new webpack.BannerPlugin({
banner: requireSourceMapSupport,
raw: true,
entryOnly: false,
}),
// Ignore annoying isomorphic-fetch / cross-fetch encoding/iconv-loader warning
// "Critical dependency: the request of a dependency is an expression"
new webpack.IgnorePlugin(/\/iconv-loader$/),
],
// sourcemaps
devtool: "#source-map",
};
};