Skip to content

Commit

Permalink
perf: Use thread-loader
Browse files Browse the repository at this point in the history
  • Loading branch information
memoyil committed Jan 19, 2025
1 parent b38e244 commit 5d19ac1
Show file tree
Hide file tree
Showing 4 changed files with 263 additions and 238 deletions.
31 changes: 0 additions & 31 deletions apps/web/biome.json

This file was deleted.

74 changes: 39 additions & 35 deletions apps/web/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const sentryWebpackPluginOptions =
validate: true,
hideSourceMaps: false,
tryRun: true,
disable: true
disable: true,
// https://github.com/getsentry/sentry-webpack-plugin#options.
}
: {
Expand All @@ -50,11 +50,6 @@ const config = {
typescript: {
tsconfigPath: 'tsconfig.json',
},
eslint: {
// Warning: This allows production builds to successfully complete even if
// your project has ESLint errors.
ignoreDuringBuilds: true,
},
compiler: {
styledComponents: true,
},
Expand Down Expand Up @@ -226,46 +221,55 @@ const config = {
},
]
},
webpack: (webpackConfig, { webpack, isServer }) => {
webpack: (webpackConfig, { webpack, isServer, defaultLoaders }) => {
// tree shake sentry tracing
webpackConfig.plugins.push(
new webpack.DefinePlugin({
__SENTRY_DEBUG__: false,
__SENTRY_TRACING__: false,
}),
)
webpackConfig.plugins.push(
new RetryChunkLoadPlugin({
cacheBust: `function() {
if (!isServer) {
webpackConfig.module.rules.push({
test: /\.js$/,
use: [
'thread-loader',
defaultLoaders.babel
],
})
webpackConfig.plugins.push(
new RetryChunkLoadPlugin({
cacheBust: `function() {
return 'cache-bust=' + Date.now();
}`,
retryDelay: `function(retryAttempt) {
retryDelay: `function(retryAttempt) {
return 2 ** (retryAttempt - 1) * 500;
}`,
maxRetries: 5,
}),
)
webpackConfig.optimization.minimize = true
webpackConfig.optimization.minimizer = [
new TerserPlugin({
parallel: true,
minify: TerserPlugin.esbuildMinify,
terserOptions: {},
}),
]
if (!isServer && webpackConfig.optimization.splitChunks) {
// webpack doesn't understand worker deps on quote worker, so we need to manually add them
// https://github.com/webpack/webpack/issues/16895
// eslint-disable-next-line no-param-reassign
webpackConfig.optimization.splitChunks.cacheGroups.workerChunks = {
chunks: 'all',
test(module) {
const resource = module.nameForCondition?.() ?? ''
return resource ? workerDeps.some((d) => resource.includes(d)) : false
},
priority: 31,
name: 'worker-chunks',
reuseExistingChunk: true,
maxRetries: 5,
}),
)
webpackConfig.optimization.minimize = true
webpackConfig.optimization.minimizer = [
new TerserPlugin({
parallel: true,
minify: TerserPlugin.esbuildMinify,
terserOptions: {},
}),
]
if (webpackConfig.optimization.splitChunks) {
// webpack doesn't understand worker deps on quote worker, so we need to manually add them
// https://github.com/webpack/webpack/issues/16895
// eslint-disable-next-line no-param-reassign
webpackConfig.optimization.splitChunks.cacheGroups.workerChunks = {
chunks: 'all',
test(module) {
const resource = module.nameForCondition?.() ?? ''
return resource ? workerDeps.some((d) => resource.includes(d)) : false
},
priority: 31,
name: 'worker-chunks',
reuseExistingChunk: true,
}
}
}
return webpackConfig
Expand Down
5 changes: 3 additions & 2 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"test": "LC_ALL=\"en_US.UTF-8\" vitest --run",
"test:watch": "LC_ALL=\"en_US.UTF-8\" vitest --watch",
"test:config": "vitest --run --config vitest-config-test.config.ts",
"lint": "biome lint src",
"lint": "eslint 'src/**/*.{js,jsx,ts,tsx}'",
"lint:style": "npx stylelint '**/*.{ts,tsx}'",
"format:write": "prettier --write \"**/*.{js,jsx,ts,tsx,json}\"",
"typechecks": "tsc --noEmit -p ./tsconfig.json"
Expand Down Expand Up @@ -195,6 +195,7 @@
"tilg": "^0.1.1",
"typescript": "5.2.2",
"vite-tsconfig-paths": "^4.0.3",
"webpack-retry-chunk-load-plugin": "3.1.1"
"webpack-retry-chunk-load-plugin": "3.1.1",
"thread-loader": "4.0.4"
}
}
Loading

0 comments on commit 5d19ac1

Please sign in to comment.