Bluesky app fork with some witchin' additions 馃挮
1const createExpoWebpackConfigAsync = require('@expo/webpack-config')
2const {withAlias} = require('@expo/webpack-config/addons')
3const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin')
4const {BundleAnalyzerPlugin} = require('webpack-bundle-analyzer')
5const {sentryWebpackPlugin} = require('@sentry/webpack-plugin')
6const {version} = require('./package.json')
7
8const GENERATE_STATS = process.env.EXPO_PUBLIC_GENERATE_STATS === '1'
9const OPEN_ANALYZER = process.env.EXPO_PUBLIC_OPEN_ANALYZER === '1'
10
11const reactNativeWebWebviewConfiguration = {
12 test: /postMock.html$/,
13 use: {
14 loader: 'file-loader',
15 options: {
16 name: '[name].[ext]',
17 },
18 },
19}
20
21module.exports = async function (env, argv) {
22 env.babel = {
23 dangerouslyAddModulePathsToTranspile: ['@bsky.app/expo'],
24 }
25 let config = await createExpoWebpackConfigAsync(env, argv)
26 config = withAlias(config, {
27 'react-native$': 'react-native-web',
28 'react-native-webview': 'react-native-web-webview',
29 // Force ESM version
30 'unicode-segmenter/grapheme': require
31 .resolve('unicode-segmenter/grapheme')
32 .replace(/\.cjs$/, '.js'),
33 'react-native-gesture-handler': false, // RNGH should not be used on web, so let's cause a build error if it sneaks in
34 '@sentry-internal/replay': false, // not used, ~300kb of dead weight
35 })
36 config.module.rules = [
37 ...(config.module.rules || []),
38 reactNativeWebWebviewConfiguration,
39 ]
40 if (env.mode === 'development') {
41 config.plugins.push(new ReactRefreshWebpackPlugin())
42 // Reap zombie HMR WebSocket connections that linger after refresh.
43 // Without this, dead sockets exhaust the browser's per-origin connection
44 // pool and the dev server stops responding.
45 config.devServer.onListening = devServer => {
46 devServer.server.on('connection', socket => {
47 socket.setTimeout(10000)
48 socket.on('timeout', () => socket.destroy())
49 })
50 }
51 } else {
52 // Support static CDN for chunks
53 config.output.publicPath = 'auto'
54 }
55
56 if (GENERATE_STATS || OPEN_ANALYZER) {
57 config.plugins.push(
58 new BundleAnalyzerPlugin({
59 openAnalyzer: OPEN_ANALYZER,
60 generateStatsFile: true,
61 statsFilename: '../stats.json',
62 analyzerMode: OPEN_ANALYZER ? 'server' : 'json',
63 defaultSizes: 'parsed',
64 }),
65 )
66 }
67 if (process.env.SENTRY_AUTH_TOKEN) {
68 config.plugins.push(
69 sentryWebpackPlugin({
70 org: 'blueskyweb',
71 project: 'app',
72 authToken: process.env.SENTRY_AUTH_TOKEN,
73 release: {
74 // fallback needed for Render.com deployments
75 name: process.env.SENTRY_RELEASE || version,
76 dist: process.env.SENTRY_DIST,
77 },
78 }),
79 )
80 }
81 return config
82}