Skip to content

Commit eb45a6d

Browse files
committed
Merge branch 'webpack-v5'
2 parents d23b6a1 + 8aaadeb commit eb45a6d

19 files changed

+4831
-6313
lines changed

automation/tsconfig.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@
1313
]
1414
},
1515
"files": [],
16-
"include": []
16+
"include": [
17+
"../custom-typings/**/*.d.ts"
18+
]
1719
}

automation/webpack.common.ts

+45-23
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as path from 'path';
22
import * as Webpack from 'webpack';
33

44
import HtmlWebpackPlugin from 'html-webpack-plugin';
5-
import GoogleFontsPlugin from 'google-fonts-plugin';
5+
import GoogleFontsPlugin from '@beyonk/google-fonts-webpack-plugin';
66
import CopyPlugin from 'copy-webpack-plugin';
77
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
88
import ForkTsCheckerNotifierWebpackPlugin from 'fork-ts-checker-notifier-webpack-plugin';
@@ -19,15 +19,33 @@ export default <Webpack.Configuration>{
1919

2020
output: {
2121
path: OUTPUT_DIR,
22-
filename: 'app.js',
22+
filename: '[name].js',
2323
chunkFilename: '[name].bundle.js',
24-
// https://github.com/webpack-contrib/worker-loader/issues/142
25-
// Stops HMR breaking worker-loader
26-
globalObject: 'this'
24+
clean: true
2725
},
2826

2927
resolve: {
30-
extensions: ['.mjs', '.js', '.ts', '.tsx', '.json']
28+
extensions: ['.mjs', '.ts', '.tsx', '...'],
29+
fallback: {
30+
fs: false,
31+
net: false,
32+
tls: false,
33+
http: false,
34+
35+
assert: require.resolve('assert/'),
36+
crypto: require.resolve('crypto-browserify'),
37+
path: require.resolve('path-browserify'),
38+
process: require.resolve('process/browser'),
39+
querystring: require.resolve('querystring-es3'),
40+
stream: require.resolve('stream-browserify'),
41+
buffer: require.resolve('buffer/'),
42+
url: require.resolve('url/'),
43+
util: require.resolve('util/'),
44+
zlib: require.resolve('browserify-zlib')
45+
},
46+
alias: {
47+
mockrtc$: path.resolve(__dirname, '../node_modules/mockrtc/dist/main-browser.js')
48+
}
3149
},
3250

3351
stats: {
@@ -46,7 +64,6 @@ export default <Webpack.Configuration>{
4664
rules: [{
4765
test: /\.tsx?$/,
4866
use: [
49-
{ loader: 'cache-loader' },
5067
{
5168
loader: 'thread-loader',
5269
options: {
@@ -69,8 +86,8 @@ export default <Webpack.Configuration>{
6986
],
7087
exclude: /node_modules/
7188
}, {
72-
test: /\.(woff2|ttf|png|svg)$/,
73-
loader: 'file-loader'
89+
test: /\.(png|svg)$/,
90+
type: 'asset/resource'
7491
}, {
7592
test: /\.mjs$/,
7693
include: /node_modules/,
@@ -80,18 +97,15 @@ export default <Webpack.Configuration>{
8097
use: ['style-loader', 'css-loader']
8198
}, {
8299
test: /amiusing.html$/,
83-
use: 'raw-loader'
100+
type: 'asset/source'
84101
}, {
85102
test: /node_modules[\\|/]typesafe-get/,
86103
use: { loader: 'umd-compat-loader' }
87104
}]
88105
},
89106

90-
node: {
91-
process: true,
92-
fs: 'empty',
93-
net: 'empty',
94-
tls: 'empty'
107+
experiments: {
108+
asyncWebAssembly: true
95109
},
96110

97111
plugins: [
@@ -106,18 +120,21 @@ export default <Webpack.Configuration>{
106120
}
107121
}),
108122
new ForkTsCheckerNotifierWebpackPlugin(),
109-
new Webpack.IgnorePlugin(
123+
new Webpack.IgnorePlugin({
110124
// Fallback, only used in wasm isn't supported. We just don't support zstd
111125
// if wasm isn't supported (i.e. if loaded custom in old old browsers).
112-
/\/zstd-codec-binding.js$/, /zstd-codec/
113-
),
126+
resourceRegExp: /\/zstd-codec-binding.js$/,
127+
contextRegExp: /zstd-codec/
128+
}),
114129
new HtmlWebpackPlugin({
115130
template: path.join(SRC_DIR, 'index.html')
116131
}),
117-
new CopyPlugin([
118-
{ from: 'node_modules/openapi-directory/api', to: 'api' },
119-
{ from: './extra-apis', to: 'api' },
120-
]),
132+
new CopyPlugin({
133+
patterns: [
134+
{ from: 'node_modules/openapi-directory/api', to: 'api' },
135+
{ from: './extra-apis', to: 'api' },
136+
]
137+
}),
121138
new MonacoWebpackPlugin({
122139
languages: [
123140
'html',
@@ -153,7 +170,12 @@ export default <Webpack.Configuration>{
153170
{ family: "Lato" }
154171
],
155172
formats: ['woff2'], // Supported by Chrome, FF, Edge, Safari 12+
156-
filename: 'fonts.css'
173+
filename: 'fonts.css',
174+
apiUrl: 'https://gwfh.mranftl.com/api/fonts'
175+
}),
176+
new Webpack.ProvidePlugin({
177+
'process': 'process/browser.js',
178+
'Buffer': ['buffer', 'Buffer']
157179
}),
158180
new Webpack.EnvironmentPlugin({
159181
'SENTRY_DSN': null,

automation/webpack.dev.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as path from "path";
2+
import * as Webpack from 'webpack';
23

34
import merge from 'webpack-merge';
45
import common from './webpack.common';
@@ -9,9 +10,7 @@ export default merge(common, {
910
devtool: 'eval-cheap-module-source-map' as any,
1011

1112
devServer: {
12-
contentBase: common.output!.path!,
1313
host: '127.0.0.1',
14-
public: 'local.httptoolkit.tech:8080',
1514
historyApiFallback: true
1615
},
1716

@@ -25,9 +24,16 @@ export default merge(common, {
2524
path.join(__dirname, '..', 'node_modules', 'monaco-editor'),
2625
path.join(__dirname, '..', 'node_modules', 'subscriptions-transport-ws'),
2726
path.join(__dirname, '..', '..', 'mockttp', 'node_modules', 'subscriptions-transport-ws'),
28-
path.join(__dirname, '..', 'node_modules', 'js-beautify')
27+
path.join(__dirname, '..', 'node_modules', 'js-beautify'),
28+
path.join(__dirname, '..', 'node_modules', 'graphql-subscriptions'),
2929
]
3030
}
3131
]
32-
}
32+
},
33+
34+
plugins: [
35+
new Webpack.DefinePlugin({
36+
'process.env.DISABLE_UPDATES': 'true'
37+
})
38+
]
3339
});

automation/webpack.prod.ts

+36-7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import SentryPlugin from '@sentry/webpack-plugin';
55
import { InjectManifest } from 'workbox-webpack-plugin';
66
import * as ssri from "ssri";
77

8+
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
9+
810
import common from "./webpack.common";
911

1012
const shouldPublishSentryRelease =
@@ -22,16 +24,38 @@ export default merge(common, {
2224
// Automatically split into source/vendor bundle chunks.
2325
// Here because this breaks TS-node in the tests, not clear why.
2426
optimization: {
27+
chunkIds: 'named',
2528
splitChunks: {
26-
chunks: (chunk) => {
27-
// React monaco editor is 99.99% vendor code, so splitting it
28-
// just creates an absurdly tiny extra bundle.
29-
return chunk.name !== "react-monaco-editor";
30-
},
29+
chunks: 'all',
30+
31+
// Split out various extra chunks for libraries that we know to be large & either
32+
// rarely used or updated differently to other code in the frontend. The goal is to
33+
// avoid re-downloading large non-updated libs when often-updated libs change.
34+
// This is a bit suspect - definitely more art then science right now.
3135
cacheGroups: {
36+
// Zstd is rarely used, big-ish, always loaded async, and v rarely changed:
3237
zstd: {
3338
test: /[\\/]node_modules[\\/]zstd-codec[\\/]/,
34-
name: "zstd"
39+
name: 'zstd'
40+
},
41+
42+
// Monaco is loaded async, v large, and rarely changed:
43+
monaco: {
44+
test: /[\\/]node_modules[\\/](monaco-editor|react-monaco-editor)[\\/]/,
45+
name: 'monaco'
46+
},
47+
48+
// APIs change on a completely independent schedule to anything else:
49+
apis: {
50+
test: /[\\/]node_modules[\\/]openapi-directory[\\/]/,
51+
name: 'apis'
52+
},
53+
54+
// Mockttp is relatively frequently changed, so pulling it into
55+
// a separate chunk avoids churn elsewhere:
56+
mockttp: {
57+
test: /[\\/]node_modules[\\/]mockttp[\\/]/,
58+
name: 'mockttp'
3559
}
3660
}
3761
}
@@ -77,6 +101,11 @@ export default merge(common, {
77101
validate: true
78102
})
79103
]
80-
: [])
104+
: []),
105+
new BundleAnalyzerPlugin({
106+
analyzerMode: 'static',
107+
openAnalyzer: false,
108+
excludeAssets: /api\/.*\.json/
109+
})
81110
]
82111
});

automation/webpack.unittest.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
import * as _ from 'lodash';
2+
import * as Webpack from 'webpack';
3+
24
import * as tmp from 'tmp';
35
tmp.setGracefulCleanup();
46

57
import commonConfig from './webpack.common';
68

79
commonConfig.mode = 'development';
810
commonConfig.entry = undefined;
9-
commonConfig.plugins = undefined;
11+
commonConfig.plugins = [
12+
new Webpack.ProvidePlugin({
13+
'process': 'process/browser.js',
14+
'Buffer': ['buffer', 'Buffer']
15+
}),
16+
];
1017
commonConfig.output = {
1118
path: tmp.dirSync().name,
1219
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
declare module '@beyonk/google-fonts-webpack-plugin';

0 commit comments

Comments
 (0)