Skip to content

Commit 45a24e0

Browse files
silverwindGiteaBot
authored andcommitted
Enable production source maps for index.js, fix CSS sourcemaps (go-gitea#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 go-gitea#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.
1 parent fee8522 commit 45a24e0

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

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

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

131-
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.
132-
133131
## Test
134132

135133
After following the steps above, a `gitea` binary will be available in the working directory.
@@ -260,3 +258,11 @@ GOARCH=amd64 \
260258
TAGS="bindata sqlite sqlite_unlock_notify" \
261259
make build
262260
```
261+
262+
## Source Maps
263+
264+
By default, gitea generates reduced source maps for frontend files to conserve space. This can be controlled with the `ENABLE_SOURCEMAP` environment variable:
265+
266+
- `ENABLE_SOURCEMAP=true` generates all source maps, the default for development builds
267+
- `ENABLE_SOURCEMAP=reduced` generates limited source maps, the default for production builds
268+
- `ENABLE_SOURCEMAP=false` generates no source maps

docs/content/installation/from-source.zh-cn.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,6 @@ TAGS="bindata sqlite sqlite_unlock_notify" make build
100100
TAGS="bindata" make backend
101101
```
102102

103-
在开发构建中,默认启用 Webpack 源映射,在生产构建中禁用。可以通过设置`ENABLE_SOURCEMAP=true`环境变量来启用它们。
104-
105103
## 测试
106104

107105
按照上述步骤完成后,工作目录中将会有一个`gitea`二进制文件。可以从该目录进行测试,或将其移动到带有测试数据的目录中。当手动从命令行启动 Gitea 时,可以通过按下`Ctrl + C`来停止程序。
@@ -221,3 +219,11 @@ GOARCH=amd64 \
221219
TAGS="bindata sqlite sqlite_unlock_notify" \
222220
make build
223221
```
222+
223+
## 源映射
224+
225+
默认情况下,gitea 会为前端文件生成精简的源映射以节省空间。 这可以通过“ENABLE_SOURCEMAP”环境变量进行控制:
226+
227+
- `ENABLE_SOURCEMAP=true` 生成所有源映射,这是开发版本的默认设置
228+
- `ENABLE_SOURCEMAP=reduced` 生成有限的源映射,这是生产版本的默认设置
229+
- `ENABLE_SOURCEMAP=false` 不生成源映射

webpack.config.js

+14-7
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,15 @@ for (const path of glob('web_src/css/themes/*.css')) {
2828

2929
const isProduction = env.NODE_ENV !== 'development';
3030

31-
let sourceMapEnabled;
31+
// ENABLE_SOURCEMAP accepts the following values:
32+
// true - all enabled, the default in development
33+
// reduced - minimal sourcemaps, the default in production
34+
// false - all disabled
35+
let sourceMaps;
3236
if ('ENABLE_SOURCEMAP' in env) {
33-
sourceMapEnabled = env.ENABLE_SOURCEMAP === 'true';
37+
sourceMaps = ['true', 'false'].includes(env.ENABLE_SOURCEMAP) ? env.ENABLE_SOURCEMAP : 'reduced';
3438
} else {
35-
sourceMapEnabled = !isProduction;
39+
sourceMaps = isProduction ? 'reduced' : 'true';
3640
}
3741

3842
const filterCssImport = (url, ...args) => {
@@ -105,7 +109,9 @@ export default {
105109
css: !LightningCssMinifyPlugin,
106110
legalComments: 'none',
107111
}),
108-
LightningCssMinifyPlugin && new LightningCssMinifyPlugin(),
112+
LightningCssMinifyPlugin && new LightningCssMinifyPlugin({
113+
sourceMap: sourceMaps === 'true',
114+
}),
109115
],
110116
splitChunks: {
111117
chunks: 'async',
@@ -143,7 +149,7 @@ export default {
143149
{
144150
loader: 'css-loader',
145151
options: {
146-
sourceMap: sourceMapEnabled,
152+
sourceMap: sourceMaps === 'true',
147153
url: {filter: filterCssImport},
148154
import: {filter: filterCssImport},
149155
},
@@ -181,9 +187,10 @@ export default {
181187
filename: 'css/[name].css',
182188
chunkFilename: 'css/[name].[contenthash:8].css',
183189
}),
184-
sourceMapEnabled && (new SourceMapDevToolPlugin({
190+
sourceMaps !== 'false' && new SourceMapDevToolPlugin({
185191
filename: '[file].[contenthash:8].map',
186-
})),
192+
...(sourceMaps === 'reduced' && {include: /^js\/index\.js$/}),
193+
}),
187194
new MonacoWebpackPlugin({
188195
filename: 'js/monaco-[name].[contenthash:8].worker.js',
189196
}),

0 commit comments

Comments
 (0)