forked from artsy/force
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbaseConfig.js
156 lines (152 loc) · 4.32 KB
/
baseConfig.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
147
148
149
150
151
152
153
154
155
156
// @ts-check
const path = require("path")
const webpack = require("webpack")
const LoadablePlugin = require("@loadable/webpack-plugin")
const { RetryChunkLoadPlugin } = require("webpack-retry-chunk-load-plugin")
const { getEntrypoints } = require("../utils/getEntrypoints")
const {
BUILD_SERVER,
NODE_ENV,
basePath,
isCI,
} = require("../../src/lib/environment")
exports.baseConfig = {
mode: NODE_ENV,
devtool: "source-map",
stats: "normal", // or, `errors-only`
entry: getEntrypoints(),
output: {
filename: "[name].js",
path: path.resolve(basePath, "public/assets"),
publicPath: "/assets/",
},
module: {
rules: [
{
test: /\.coffee$/,
include: path.resolve(basePath, "src"),
use: ["cache-loader", "coffee-loader"],
},
{
test: /\.(jade|pug)$/,
include: path.resolve(basePath, "src"),
use: [
{
loader: "pug-loader",
options: {
doctype: "html",
root: __dirname,
},
},
],
},
{
test: /(\.(js|ts)x?$)/,
include: path.resolve(basePath, "src"),
use: [
{
loader: "babel-loader",
options: {
cacheDirectory: !isCI && path.join(basePath, ".cache", "babel"),
},
},
],
},
// ESM support. See: https://github.com/apollographql/react-apollo/issues/1737#issuecomment-371178602
{
type: "javascript/auto",
test: /\.mjs$/,
use: [],
},
],
},
plugins: [
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify(NODE_ENV),
},
}),
// Remove moment.js localization files
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
// Remove server-only modules from client bundles
...(BUILD_SERVER
? []
: [
// Remove server side of relay network layer.
new webpack.IgnorePlugin(
/^react-relay-network-modern-ssr\/node8\/server/
),
// No matter what, we don't want the graphql-js package in client
// bundles. This /may/ lead to a broken build when e.g. a reaction
// module that's used on the client side imports something from
// graphql-js, but that's better than silently including this.
new webpack.IgnorePlugin(/^graphql(\/.*)?$/),
]),
new webpack.NamedModulesPlugin(),
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
"window.jQuery": "jquery",
jade: "jade/runtime.js",
waypoints: "jquery-waypoints/waypoints.js",
}),
new LoadablePlugin(),
/**
* If something goes wrong while loading a dynmic split chunk (import())
* retry the fetch once per second up to `maxRetries`.
*
* NOTE: Since this plugin patches the native loading mechanism from webpack
* we (may) need to revist once we upgrade to Webpack 5.
*/
new RetryChunkLoadPlugin({
maxRetries: 5,
cacheBust: `function() {
return "cache-bust=" + Date.now();
}`,
}),
],
resolve: {
alias: {
"jquery.ui.widget": "blueimp-file-upload/js/vendor/jquery.ui.widget.js",
// The following packages need to be resolved to the host app (force) to get
// around issues involving `yarn link` and multiple instances. A similar
// configuration has been setup for SSR in `src/index`, via `require-control`.
"styled-components": require.resolve("styled-components"),
react: require.resolve("react"),
},
extensions: [
".mjs",
".js",
".jsx",
".ts",
".tsx",
".json",
".jade",
".coffee",
],
// Symlink issues should be fixed via `yarn --pnp`
modules: [path.resolve(basePath, "src"), "node_modules"],
symlinks: false,
},
optimization: {
// Extract webpack runtime code into it's own file
runtimeChunk: {
name: "runtime-manifest",
},
splitChunks: {
cacheGroups: {
// Separate vendor libraries from `node_modules` into a `commons.js`
commons: {
test: /[\\/]node_modules[\\/]/,
name: "common",
minChunks: 10,
chunks: "initial",
},
},
},
},
externals: {
// Don't bundle modules and consider them external
request: "request",
},
}