aboutsummaryrefslogtreecommitdiffstats
path: root/webpack.config.js
diff options
context:
space:
mode:
authorsilverwind <me@silverwind.io>2023-09-27 04:05:49 +0200
committerGitHub <noreply@github.com>2023-09-26 22:05:49 -0400
commitc5247eff73ea0be33affb97d666c9d222aabcc37 (patch)
treeb5b7a5613e3c54518755be89e923c86840e9f744 /webpack.config.js
parent6967c13ad2de927f4d9bad65930db5fb383ca1d4 (diff)
downloadgitea-c5247eff73ea0be33affb97d666c9d222aabcc37.tar.gz
gitea-c5247eff73ea0be33affb97d666c9d222aabcc37.zip
Enable production source maps for index.js, fix CSS sourcemaps (#27291)
Previously, the production build never output sourcemaps. Now we emit one file for `index.js` because it is the most likely one where we need to be able to better debug reported issues like https://github.com/go-gitea/gitea/issues/27213. This will currently increase the binary size of gitea by around 700kB which is what the gzipped source map file has. Also, I fixed the CSS sourcemap generation which was broken since the introduction of lightningcss.
Diffstat (limited to 'webpack.config.js')
-rw-r--r--webpack.config.js21
1 files changed, 14 insertions, 7 deletions
diff --git a/webpack.config.js b/webpack.config.js
index f95296c380..448dc64003 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -28,11 +28,15 @@ for (const path of glob('web_src/css/themes/*.css')) {
const isProduction = env.NODE_ENV !== 'development';
-let sourceMapEnabled;
+// ENABLE_SOURCEMAP accepts the following values:
+// true - all enabled, the default in development
+// reduced - minimal sourcemaps, the default in production
+// false - all disabled
+let sourceMaps;
if ('ENABLE_SOURCEMAP' in env) {
- sourceMapEnabled = env.ENABLE_SOURCEMAP === 'true';
+ sourceMaps = ['true', 'false'].includes(env.ENABLE_SOURCEMAP) ? env.ENABLE_SOURCEMAP : 'reduced';
} else {
- sourceMapEnabled = !isProduction;
+ sourceMaps = isProduction ? 'reduced' : 'true';
}
const filterCssImport = (url, ...args) => {
@@ -105,7 +109,9 @@ export default {
css: !LightningCssMinifyPlugin,
legalComments: 'none',
}),
- LightningCssMinifyPlugin && new LightningCssMinifyPlugin(),
+ LightningCssMinifyPlugin && new LightningCssMinifyPlugin({
+ sourceMap: sourceMaps === 'true',
+ }),
],
splitChunks: {
chunks: 'async',
@@ -143,7 +149,7 @@ export default {
{
loader: 'css-loader',
options: {
- sourceMap: sourceMapEnabled,
+ sourceMap: sourceMaps === 'true',
url: {filter: filterCssImport},
import: {filter: filterCssImport},
},
@@ -181,9 +187,10 @@ export default {
filename: 'css/[name].css',
chunkFilename: 'css/[name].[contenthash:8].css',
}),
- sourceMapEnabled && (new SourceMapDevToolPlugin({
+ sourceMaps !== 'false' && new SourceMapDevToolPlugin({
filename: '[file].[contenthash:8].map',
- })),
+ ...(sourceMaps === 'reduced' && {include: /^js\/index\.js$/}),
+ }),
new MonacoWebpackPlugin({
filename: 'js/monaco-[name].[contenthash:8].worker.js',
}),