Skip to content

Commit

Permalink
make prod build faster than dev
Browse files Browse the repository at this point in the history
  • Loading branch information
zardoy committed Aug 18, 2023
1 parent 9137f88 commit a20a3fc
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"compression": "^1.7.4",
"cypress-plugin-snapshots": "^1.4.4",
"diamond-square": "^1.2.0",
"esbuild-loader": "^4.0.0",
"esbuild-plugin-polyfill-node": "^0.3.0",
"express": "^4.18.2",
"fs-extra": "^11.1.1",
Expand All @@ -48,7 +49,6 @@
"space-squid": "github:zardoy/space-squid",
"speed-measure-webpack-plugin": "^1.5.0",
"stats.js": "^0.17.0",
"ts-loader": "^9.4.4",
"url": "^0.11.1",
"valtio": "^1.11.1"
},
Expand Down
15 changes: 6 additions & 9 deletions webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,12 @@ const config = {
module: {
rules: [
{
test: /\.ts$/,
use: [
{
loader: 'ts-loader',
options: {
transpileOnly: true,
},
},
],
test: /\.tsx?$/,
loader: 'esbuild-loader',
// options: {
// // JavaScript version to compile to
// target: 'es2015'
// }
},
],
},
Expand Down
4 changes: 4 additions & 0 deletions webpack.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ module.exports = merge(common,
mode: 'development',
devtool: 'inline-source-map',
cache: true,
// experiments: {
// cacheUnaffected: true,
// },
devServer: {
// contentBase: path.resolve(__dirname, './public'),
compress: true,
Expand All @@ -23,6 +26,7 @@ module.exports = merge(common,
},
optimization: {
splitChunks: {
chunks: 'all',
maxAsyncRequests: 10,
maxInitialRequests: 10,
cacheGroups: {
Expand Down
21 changes: 16 additions & 5 deletions webpack.prod.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { merge } = require('webpack-merge')
const common = require('./webpack.common.js')
const { EsbuildPlugin } = require('esbuild-loader')

const LodashModuleReplacementPlugin = require('lodash-webpack-plugin')
const WorkboxPlugin = require('workbox-webpack-plugin')
Expand All @@ -14,6 +15,14 @@ module.exports = merge(common, {
filename: './[name].js',
},
mode: 'production',
optimization: {
minimizer: [
new EsbuildPlugin({
// would be better to use 2019 with polyfilling bigints (disabling them?)
target: 'es2021' // Syntax to transpile to (see options below for possible values)
})
]
},
devtool: 'source-map',
plugins: [
new webpack.optimize.ModuleConcatenationPlugin(),
Expand All @@ -27,11 +36,13 @@ module.exports = merge(common, {
maximumFileSizeToCacheInBytes: 35_000_000, // todo will be lowered
exclude: [/\.map$/, 'version.txt']
}),
new webpack.DefinePlugin({
// get from github actions or vercel env
'process.env.BUILD_VERSION': JSON.stringify(buildingVersion),
'process.env.GITHUB_URL':
JSON.stringify(`https://github.com/${process.env.GITHUB_REPOSITORY || `${process.env.VERCEL_GIT_REPO_OWNER}/${process.env.VERCEL_GIT_REPO_SLUG}`}`)
new EsbuildPlugin({
define: {
// get from github actions or vercel env
'process.env.BUILD_VERSION': JSON.stringify(buildingVersion),
'process.env.GITHUB_URL':
JSON.stringify(`https://github.com/${process.env.GITHUB_REPOSITORY || `${process.env.VERCEL_GIT_REPO_OWNER}/${process.env.VERCEL_GIT_REPO_SLUG}`}`)
}
})
],
})

0 comments on commit a20a3fc

Please sign in to comment.