-
Notifications
You must be signed in to change notification settings - Fork 0
/
development.config.js
258 lines (253 loc) · 7.64 KB
/
development.config.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
/* eslint-disable import/no-commonjs, import/no-nodejs-modules, func-style */
const path = require("path");
const {HashedModuleIdsPlugin} = require("webpack");
const {HotModuleReplacementPlugin} = require("webpack");
// const WebpackNodeExternals = require("webpack-node-externals");
const {IgnorePlugin} = require("webpack");
const {EnvironmentPlugin} = require("webpack");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const CompressionWebpackPlugin = require("compression-webpack-plugin");
const {CleanWebpackPlugin} = require("clean-webpack-plugin");
const {BundleAnalyzerPlugin} = require("webpack-bundle-analyzer");
const {Plugin: WebpackCommonShake} = require("webpack-common-shake");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const WebpackAssetsManifest = require("webpack-assets-manifest");
const WebpackSubresourceIntegrity = require("webpack-subresource-integrity");
const DotenvWebpack = require("dotenv-webpack");
const {config: dotenvConfiguration} = require("dotenv");
const {compact} = require("@unction/complete");
const {mergeDeepRight} = require("@unction/complete");
dotenvConfiguration();
const BENCHMARK = process.env.BENCHMARK === "enabled";
const NODE_ENV = process.env.NODE_ENV || "development";
const PRODUCTION = NODE_ENV === "production";
const DEVTOOL = PRODUCTION ? "source-map" : "inline-source-map";
const PACKAGE_ASSETS = [];
const SHARED_BUILD_CONFIGURATION = {
mode: NODE_ENV,
devtool: DEVTOOL,
module: {
rules: [
{
test: /index\.js$/u,
exclude: /node_modules/u,
use: {
loader: "babel-loader",
},
},
{
test: /\.gql$/u,
exclude: /node_modules/u,
loader: "graphql-tag/loader",
},
],
},
};
const PRE_SHARED_PLUGINS = [
PRODUCTION ? null : new DotenvWebpack(),
new EnvironmentPlugin([
"NODE_ENV",
"BENCHMARK",
"COUCHDB_USERNAME",
"COUCHDB_PASSWORD",
"COUCHDB_URI",
]),
PRODUCTION ? new CleanWebpackPlugin({verbose: true}) : null,
];
const POST_SHARED_PLUGINS = [
PRODUCTION ? new CompressionWebpackPlugin({
filename: "[path].br[query]",
algorithm: "brotliCompress",
compressionOptions: {level: 11},
test: /\.(?:js|css|txt|xml|json|png|svg|jpg|gif|woff|woff2|eot|ttf|otf)$/iu,
}) : null,
PRODUCTION ? new CompressionWebpackPlugin({
test: /\.(?:js|css|txt|xml|json|png|svg|jpg|gif|woff|woff2|eot|ttf|otf)$/iu,
}) : null,
new WebpackCommonShake(),
BENCHMARK ? new BundleAnalyzerPlugin({analyzerMode: "static", openAnalyzer: false}) : null,
];
function clientFor (name, target, configuration = {}) {
return mergeDeepRight({
...SHARED_BUILD_CONFIGURATION,
entry: [
`./${name}/index.js`,
],
target,
output: {
publicPath: PRODUCTION ? "/assets/" : "/",
path: path.resolve(__dirname, "tmp", name.split("-")[0], PRODUCTION ? "assets" : ""),
filename: "[name].[hash].js",
chunkFilename: "[id].[chunkhash].js",
},
optimization: {
minimize: PRODUCTION,
runtimeChunk: "single",
splitChunks: {
minSize: 0,
maxAsyncRequests: Infinity,
maxInitialRequests: Infinity,
cacheGroups: {
internal: {
test: /@internal[\\/]/u,
chunks: "initial",
priority: -40,
},
unction: {
test: /[\\/]node_modules[\\/]@unction/u,
chunks: "initial",
priority: -30,
},
ramda: {
test: /[\\/]node_modules[\\/]ramda/u,
chunks: "initial",
priority: -30,
},
moment: {
test: /[\\/]node_modules[\\/]moment/u,
chunks: "initial",
priority: -20,
},
most: {
test: /[\\/]node_modules[\\/]most/u,
chunks: "initial",
priority: -20,
},
elliptic: {
test: /[\\/]node_modules[\\/]elliptic/u,
chunks: "initial",
priority: -20,
},
bn: {
test: /[\\/]node_modules[\\/]bn/u,
chunks: "initial",
priority: -20,
},
redux: {
test: /[\\/]node_modules[\\/]redux/u,
chunks: "initial",
priority: -20,
},
react: {
test: /[\\/]node_modules[\\/]react(?:-dom|-router|-router-dom|-redux)?[\\/]/u,
chunks: "initial",
priority: -20,
},
babel: {
test: /[\\/]node_modules[\\/]@babel/u,
chunks: "initial",
priority: -20,
},
corejs: {
test: /[\\/]node_modules[\\/]core-js/u,
chunks: "initial",
priority: -20,
},
pouchdb: {
test: /[\\/]node_modules[\\/](?:pouchdb|lunr)/u,
chunks: "initial",
priority: -20,
},
vendors: {
test: /[\\/]node_modules[\\/]/u,
chunks: "initial",
priority: -40,
},
},
},
},
devServer: {
contentBase: path.join(__dirname, "tmp", name.split("-")[0]),
compress: true,
historyApiFallback: true,
hot: true,
overlay: true,
},
plugins: compact([
...PRE_SHARED_PLUGINS,
new CopyWebpackPlugin([{
from: path.resolve(__dirname, "assets"),
to: path.resolve(__dirname, "tmp", name.split("-")[0], "assets"),
}]),
...PACKAGE_ASSETS.map(([from, ...to]) => new CopyWebpackPlugin([{
from,
to: path.resolve(__dirname, "tmp", name.split("-")[0], "assets", ...to),
}])),
PRODUCTION ? null : new HotModuleReplacementPlugin(),
PRODUCTION ? new IgnorePlugin(/^\.\/locale$/u, /moment$/u) : null,
new HtmlWebpackPlugin({
minify: {
removeComments: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
minifyJS: true,
minifyCSS: true,
},
hash: true,
template: path.join(__dirname, "..", "..", "templates", "index.html"),
}),
new HashedModuleIdsPlugin(),
PRODUCTION ? new WebpackSubresourceIntegrity({
hashFuncNames: ["sha256", "sha384"],
enabled: true,
}) : null,
new WebpackAssetsManifest({
output: "asset-integrity-manifest.json",
integrity: PRODUCTION,
}),
...POST_SHARED_PLUGINS,
]),
})(
configuration
);
}
function serverFor (name, target, configuration = {}) {
return mergeDeepRight({
...SHARED_BUILD_CONFIGURATION,
entry: [
`./${name}/index.js`,
],
target,
node: {
__dirname: false,
__filename: false,
},
output: {
path: path.resolve(__dirname, "tmp", name.split("-")[0]),
},
optimization: {
minimize: PRODUCTION,
},
plugins: compact([
...PRE_SHARED_PLUGINS,
PRODUCTION ? new IgnorePlugin(/^\.\/locale$/u, /moment$/u) : null,
new CopyWebpackPlugin([{
from: path.resolve(__dirname, "assets"),
to: path.resolve(__dirname, "tmp", name.split("-")[0], "assets"),
}]),
...PACKAGE_ASSETS.map(([from, ...to]) => new CopyWebpackPlugin([{
from,
to: path.resolve(__dirname, "tmp", name.split("-")[0], "assets", ...to),
}])),
...POST_SHARED_PLUGINS,
]),
})(
configuration
);
}
module.exports = [
clientFor("browser-client", "web", {
devServer: {
port: 9000,
},
}),
// clientFor("desktop-client", "electron-renderer", {
// devServer: {
// port: 9001,
// },
// }),
serverFor("browser-server", "node"),
// serverFor("desktop-server", "electron-renderer"),
];