Skip to content

Commit c09f747

Browse files
authored
Enable all webpack sourcemaps in dev build, disable all in prod build (#25089)
- Enable all source maps in dev build - Disable all source maps in prod build - Provide `ENABLE_SOURCEMAP` env var to override it. I think the strange error seen in #24784 is sourcemap related, so if we enable/disable them all, it might go away. But it's most definitely a Safari bug. With all sourcemaps disabled, binary size goes down by around 1-2 MB, with all enabled it goes up by around 12MB. If +12MB is acceptable, we could also always enable them by default as fully source maps do have some debugging benefits.
1 parent 8d7893e commit c09f747

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

docs/content/doc/installation/from-source.en-us.md

+2
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ If pre-built frontend files are present it is possible to only build the backend
132132
TAGS="bindata" make backend
133133
```
134134

135+
Webpack source maps are by default enabled in development builds and disabled in production builds. They can be enabled by setting the `ENABLE_SOURCEMAP=true` environment variable.
136+
135137
## Test
136138

137139
After following the steps above, a `gitea` binary will be available in the working directory.

webpack.config.js

+13-9
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {parse, dirname} from 'node:path';
1010
import webpack from 'webpack';
1111
import {fileURLToPath} from 'node:url';
1212
import {readFileSync} from 'node:fs';
13+
import {env} from 'node:process';
1314

1415
const {EsbuildPlugin} = EsBuildLoader;
1516
const {SourceMapDevToolPlugin, DefinePlugin} = webpack;
@@ -25,7 +26,14 @@ for (const path of glob('web_src/css/themes/*.css')) {
2526
themes[parse(path).name] = [path];
2627
}
2728

28-
const isProduction = process.env.NODE_ENV !== 'development';
29+
const isProduction = env.NODE_ENV !== 'development';
30+
31+
let sourceMapEnabled;
32+
if ('ENABLE_SOURCEMAP' in env) {
33+
sourceMapEnabled = env.ENABLE_SOURCEMAP === 'true';
34+
} else {
35+
sourceMapEnabled = !isProduction;
36+
}
2937

3038
const filterCssImport = (url, ...args) => {
3139
const cssFile = args[1] || args[0]; // resourcePath is 2nd argument for url and 3rd for import
@@ -122,7 +130,7 @@ export default {
122130
{
123131
loader: 'css-loader',
124132
options: {
125-
sourceMap: true,
133+
sourceMap: sourceMapEnabled,
126134
url: {filter: filterCssImport},
127135
import: {filter: filterCssImport},
128136
},
@@ -160,13 +168,9 @@ export default {
160168
filename: 'css/[name].css',
161169
chunkFilename: 'css/[name].[contenthash:8].css',
162170
}),
163-
new SourceMapDevToolPlugin({
171+
sourceMapEnabled && (new SourceMapDevToolPlugin({
164172
filename: '[file].[contenthash:8].map',
165-
include: [
166-
'js/index.js',
167-
'css/index.css',
168-
],
169-
}),
173+
})),
170174
new MonacoWebpackPlugin({
171175
filename: 'js/monaco-[name].[contenthash:8].worker.js',
172176
}),
@@ -195,7 +199,7 @@ export default {
195199
emitError: true,
196200
allow: '(Apache-2.0 OR BSD-2-Clause OR BSD-3-Clause OR MIT OR ISC OR CPAL-1.0 OR Unlicense OR EPL-1.0 OR EPL-2.0)',
197201
}) : new AddAssetPlugin('js/licenses.txt', `Licenses are disabled during development`),
198-
],
202+
].filter(Boolean),
199203
performance: {
200204
hints: false,
201205
maxEntrypointSize: Infinity,

0 commit comments

Comments
 (0)