From e1f22acaffac3613a1e9caead1227cc0870122dc Mon Sep 17 00:00:00 2001 From: silverwind Date: Tue, 26 Sep 2023 21:50:11 +0200 Subject: [PATCH 1/8] Enable production sourcemap for index.js, fix css sourcemaps --- .../content/installation/from-source.en-us.md | 2 +- .../content/installation/from-source.zh-cn.md | 2 +- webpack.config.js | 19 ++++++++++++------- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/docs/content/installation/from-source.en-us.md b/docs/content/installation/from-source.en-us.md index ef720f0824698..b6eb0e9159f71 100644 --- a/docs/content/installation/from-source.en-us.md +++ b/docs/content/installation/from-source.en-us.md @@ -128,7 +128,7 @@ If pre-built frontend files are present it is possible to only build the backend TAGS="bindata" make backend ``` -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. +Webpack source maps are limited by default to conserve space. When `ENABLE_SOURCEMAP=true` is set, the webpack build will generate all source maps. ## Test diff --git a/docs/content/installation/from-source.zh-cn.md b/docs/content/installation/from-source.zh-cn.md index 260ccbee3c627..0addcfa14cab2 100644 --- a/docs/content/installation/from-source.zh-cn.md +++ b/docs/content/installation/from-source.zh-cn.md @@ -100,7 +100,7 @@ TAGS="bindata sqlite sqlite_unlock_notify" make build TAGS="bindata" make backend ``` -在开发构建中,默认启用 Webpack 源映射,在生产构建中禁用。可以通过设置`ENABLE_SOURCEMAP=true`环境变量来启用它们。 +默认情况下,Webpack 源映射受到限制以节省空间。 当设置`ENABLE_SOURCEMAP=true`时,webpack 构建将生成所有源映射。 ## 测试 diff --git a/webpack.config.js b/webpack.config.js index f95296c380380..b2cf7fd42d691 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -28,11 +28,13 @@ for (const path of glob('web_src/css/themes/*.css')) { const isProduction = env.NODE_ENV !== 'development'; -let sourceMapEnabled; +// The production build only generates limited sourcemaps to conserve binary size. +// When in development or when ENABLE_SOURCEMAP=true, generate all source maps. +let fullSourceMapEnabled; if ('ENABLE_SOURCEMAP' in env) { - sourceMapEnabled = env.ENABLE_SOURCEMAP === 'true'; + fullSourceMapEnabled = env.ENABLE_SOURCEMAP === 'true'; } else { - sourceMapEnabled = !isProduction; + fullSourceMapEnabled = !isProduction; } const filterCssImport = (url, ...args) => { @@ -105,7 +107,9 @@ export default { css: !LightningCssMinifyPlugin, legalComments: 'none', }), - LightningCssMinifyPlugin && new LightningCssMinifyPlugin(), + LightningCssMinifyPlugin && new LightningCssMinifyPlugin({ + sourceMap: fullSourceMapEnabled, + }), ], splitChunks: { chunks: 'async', @@ -143,7 +147,7 @@ export default { { loader: 'css-loader', options: { - sourceMap: sourceMapEnabled, + sourceMap: fullSourceMapEnabled, url: {filter: filterCssImport}, import: {filter: filterCssImport}, }, @@ -181,9 +185,10 @@ export default { filename: 'css/[name].css', chunkFilename: 'css/[name].[contenthash:8].css', }), - sourceMapEnabled && (new SourceMapDevToolPlugin({ + new SourceMapDevToolPlugin({ filename: '[file].[contenthash:8].map', - })), + ...(!fullSourceMapEnabled && {include: /^js\/index\.js$/}), + }), new MonacoWebpackPlugin({ filename: 'js/monaco-[name].[contenthash:8].worker.js', }), From 7550533d7c5232a37df836ebb1288f1a1df08610 Mon Sep 17 00:00:00 2001 From: silverwind Date: Tue, 26 Sep 2023 22:49:24 +0200 Subject: [PATCH 2/8] move to new SOURCEMAPS env var --- .../content/installation/from-source.en-us.md | 10 +++++++-- .../content/installation/from-source.zh-cn.md | 10 +++++++-- webpack.config.js | 22 ++++++++++--------- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/docs/content/installation/from-source.en-us.md b/docs/content/installation/from-source.en-us.md index b6eb0e9159f71..51e32bafb5a10 100644 --- a/docs/content/installation/from-source.en-us.md +++ b/docs/content/installation/from-source.en-us.md @@ -128,8 +128,6 @@ If pre-built frontend files are present it is possible to only build the backend TAGS="bindata" make backend ``` -Webpack source maps are limited by default to conserve space. When `ENABLE_SOURCEMAP=true` is set, the webpack build will generate all source maps. - ## Test After following the steps above, a `gitea` binary will be available in the working directory. @@ -260,3 +258,11 @@ GOARCH=amd64 \ TAGS="bindata sqlite sqlite_unlock_notify" \ make build ``` + +## Source Maps + +By default, gitea generated reduced source maps for frontend files to conserve space. This can be controlled with the `SOURCEMAPS` environment variable: + +- `SOURCEMAPS=full` generates all source maps +- `SOURCEMAPS=reduced` generates limited source maps, the default +- `SOURCEMAPS=none` generates no source maps diff --git a/docs/content/installation/from-source.zh-cn.md b/docs/content/installation/from-source.zh-cn.md index 0addcfa14cab2..d3044990a50f4 100644 --- a/docs/content/installation/from-source.zh-cn.md +++ b/docs/content/installation/from-source.zh-cn.md @@ -100,8 +100,6 @@ TAGS="bindata sqlite sqlite_unlock_notify" make build TAGS="bindata" make backend ``` -默认情况下,Webpack 源映射受到限制以节省空间。 当设置`ENABLE_SOURCEMAP=true`时,webpack 构建将生成所有源映射。 - ## 测试 按照上述步骤完成后,工作目录中将会有一个`gitea`二进制文件。可以从该目录进行测试,或将其移动到带有测试数据的目录中。当手动从命令行启动 Gitea 时,可以通过按下`Ctrl + C`来停止程序。 @@ -221,3 +219,11 @@ GOARCH=amd64 \ TAGS="bindata sqlite sqlite_unlock_notify" \ make build ``` + +## 源映射 + +默认情况下,gitea 为前端文件生成缩减的源映射以节省空间。 这可以通过“SOURCEMAPS”环境变量进行控制: + +- `SOURCEMAPS=full` 生成所有源映射 +- `SOURCEMAPS=reduced` 生成有限的源映射,默认值 +- `SOURCEMAPS=none` 不生成源映射 diff --git a/webpack.config.js b/webpack.config.js index b2cf7fd42d691..1af3038d71720 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -28,13 +28,15 @@ for (const path of glob('web_src/css/themes/*.css')) { const isProduction = env.NODE_ENV !== 'development'; -// The production build only generates limited sourcemaps to conserve binary size. -// When in development or when ENABLE_SOURCEMAP=true, generate all source maps. -let fullSourceMapEnabled; -if ('ENABLE_SOURCEMAP' in env) { - fullSourceMapEnabled = env.ENABLE_SOURCEMAP === 'true'; +// SOURCEMAPS accepts the following values: +// "none" - all disabled +// "reduced" - minimal sourcemaps, the default in production +// "full" - all enabled, the default in development +let sourceMaps; +if ('SOURCEMAPS' in env) { + sourceMaps = ['none', 'full'].includes(env.SOURCEMAPS) ? env.SOURCEMAPS : 'reduced'; } else { - fullSourceMapEnabled = !isProduction; + sourceMaps = isProduction ? 'reduced' : 'full'; } const filterCssImport = (url, ...args) => { @@ -108,7 +110,7 @@ export default { legalComments: 'none', }), LightningCssMinifyPlugin && new LightningCssMinifyPlugin({ - sourceMap: fullSourceMapEnabled, + sourceMap: sourceMaps === 'full', }), ], splitChunks: { @@ -147,7 +149,7 @@ export default { { loader: 'css-loader', options: { - sourceMap: fullSourceMapEnabled, + sourceMap: sourceMaps === 'full', url: {filter: filterCssImport}, import: {filter: filterCssImport}, }, @@ -185,9 +187,9 @@ export default { filename: 'css/[name].css', chunkFilename: 'css/[name].[contenthash:8].css', }), - new SourceMapDevToolPlugin({ + sourceMaps !== 'none' && new SourceMapDevToolPlugin({ filename: '[file].[contenthash:8].map', - ...(!fullSourceMapEnabled && {include: /^js\/index\.js$/}), + ...(sourceMaps === 'reduced' && {include: /^js\/index\.js$/}), }), new MonacoWebpackPlugin({ filename: 'js/monaco-[name].[contenthash:8].worker.js', From 11fbb816e241047a4434f02954d4cb523b1a2c46 Mon Sep 17 00:00:00 2001 From: silverwind Date: Tue, 26 Sep 2023 22:50:13 +0200 Subject: [PATCH 3/8] docs update --- docs/content/installation/from-source.en-us.md | 4 ++-- docs/content/installation/from-source.zh-cn.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/content/installation/from-source.en-us.md b/docs/content/installation/from-source.en-us.md index 51e32bafb5a10..35c3f43166ab5 100644 --- a/docs/content/installation/from-source.en-us.md +++ b/docs/content/installation/from-source.en-us.md @@ -264,5 +264,5 @@ make build By default, gitea generated reduced source maps for frontend files to conserve space. This can be controlled with the `SOURCEMAPS` environment variable: - `SOURCEMAPS=full` generates all source maps -- `SOURCEMAPS=reduced` generates limited source maps, the default -- `SOURCEMAPS=none` generates no source maps +- `SOURCEMAPS=reduced` generates limited source maps, the default for production builds +- `SOURCEMAPS=none` generates no source maps, the default for development builds diff --git a/docs/content/installation/from-source.zh-cn.md b/docs/content/installation/from-source.zh-cn.md index d3044990a50f4..7a289658879ec 100644 --- a/docs/content/installation/from-source.zh-cn.md +++ b/docs/content/installation/from-source.zh-cn.md @@ -225,5 +225,5 @@ make build 默认情况下,gitea 为前端文件生成缩减的源映射以节省空间。 这可以通过“SOURCEMAPS”环境变量进行控制: - `SOURCEMAPS=full` 生成所有源映射 -- `SOURCEMAPS=reduced` 生成有限的源映射,默认值 -- `SOURCEMAPS=none` 不生成源映射 +- `SOURCEMAPS=reduced` 生成有限的源映射,这是生产版本的默认设置 +- `SOURCEMAPS=none` 不生成源映射,这是开发版本的默认设置 From 62f4d39f523efb2e667b1efca09c8f5aa9fc48ac Mon Sep 17 00:00:00 2001 From: silverwind Date: Tue, 26 Sep 2023 22:53:19 +0200 Subject: [PATCH 4/8] fix spelling --- docs/content/installation/from-source.en-us.md | 2 +- docs/content/installation/from-source.zh-cn.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/content/installation/from-source.en-us.md b/docs/content/installation/from-source.en-us.md index 35c3f43166ab5..c61aff702c0bd 100644 --- a/docs/content/installation/from-source.en-us.md +++ b/docs/content/installation/from-source.en-us.md @@ -261,7 +261,7 @@ make build ## Source Maps -By default, gitea generated reduced source maps for frontend files to conserve space. This can be controlled with the `SOURCEMAPS` environment variable: +By default, gitea generates reduced source maps for frontend files to conserve space. This can be controlled with the `SOURCEMAPS` environment variable: - `SOURCEMAPS=full` generates all source maps - `SOURCEMAPS=reduced` generates limited source maps, the default for production builds diff --git a/docs/content/installation/from-source.zh-cn.md b/docs/content/installation/from-source.zh-cn.md index 7a289658879ec..baa143330b8e2 100644 --- a/docs/content/installation/from-source.zh-cn.md +++ b/docs/content/installation/from-source.zh-cn.md @@ -222,7 +222,7 @@ make build ## 源映射 -默认情况下,gitea 为前端文件生成缩减的源映射以节省空间。 这可以通过“SOURCEMAPS”环境变量进行控制: +默认情况下,gitea 会为前端文件生成精简的源映射以节省空间。 这可以通过“SOURCEMAPS”环境变量进行控制: - `SOURCEMAPS=full` 生成所有源映射 - `SOURCEMAPS=reduced` 生成有限的源映射,这是生产版本的默认设置 From 022a0822edc2a2ce767d16fe96409762977ea44d Mon Sep 17 00:00:00 2001 From: silverwind Date: Tue, 26 Sep 2023 22:56:20 +0200 Subject: [PATCH 5/8] docs fix --- docs/content/installation/from-source.en-us.md | 4 ++-- docs/content/installation/from-source.zh-cn.md | 4 ++-- webpack.config.js | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/content/installation/from-source.en-us.md b/docs/content/installation/from-source.en-us.md index c61aff702c0bd..3aec265463944 100644 --- a/docs/content/installation/from-source.en-us.md +++ b/docs/content/installation/from-source.en-us.md @@ -263,6 +263,6 @@ make build By default, gitea generates reduced source maps for frontend files to conserve space. This can be controlled with the `SOURCEMAPS` environment variable: -- `SOURCEMAPS=full` generates all source maps +- `SOURCEMAPS=full` generates all source maps, the default for development builds - `SOURCEMAPS=reduced` generates limited source maps, the default for production builds -- `SOURCEMAPS=none` generates no source maps, the default for development builds +- `SOURCEMAPS=none` generates no source maps diff --git a/docs/content/installation/from-source.zh-cn.md b/docs/content/installation/from-source.zh-cn.md index baa143330b8e2..1b5e729c82bb8 100644 --- a/docs/content/installation/from-source.zh-cn.md +++ b/docs/content/installation/from-source.zh-cn.md @@ -224,6 +224,6 @@ make build 默认情况下,gitea 会为前端文件生成精简的源映射以节省空间。 这可以通过“SOURCEMAPS”环境变量进行控制: -- `SOURCEMAPS=full` 生成所有源映射 +- `SOURCEMAPS=full` 生成所有源映射,这是开发版本的默认设置 - `SOURCEMAPS=reduced` 生成有限的源映射,这是生产版本的默认设置 -- `SOURCEMAPS=none` 不生成源映射,这是开发版本的默认设置 +- `SOURCEMAPS=none` 不生成源映射 diff --git a/webpack.config.js b/webpack.config.js index 1af3038d71720..a25385b2a1425 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -29,9 +29,9 @@ for (const path of glob('web_src/css/themes/*.css')) { const isProduction = env.NODE_ENV !== 'development'; // SOURCEMAPS accepts the following values: -// "none" - all disabled // "reduced" - minimal sourcemaps, the default in production // "full" - all enabled, the default in development +// "none" - all disabled let sourceMaps; if ('SOURCEMAPS' in env) { sourceMaps = ['none', 'full'].includes(env.SOURCEMAPS) ? env.SOURCEMAPS : 'reduced'; From a65fcbde73f55db428bba4ca51d8226518e46922 Mon Sep 17 00:00:00 2001 From: silverwind Date: Tue, 26 Sep 2023 22:57:16 +0200 Subject: [PATCH 6/8] comment fix --- webpack.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webpack.config.js b/webpack.config.js index a25385b2a1425..0e9c0cfdb8aca 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -29,8 +29,8 @@ for (const path of glob('web_src/css/themes/*.css')) { const isProduction = env.NODE_ENV !== 'development'; // SOURCEMAPS accepts the following values: -// "reduced" - minimal sourcemaps, the default in production // "full" - all enabled, the default in development +// "reduced" - minimal sourcemaps, the default in production // "none" - all disabled let sourceMaps; if ('SOURCEMAPS' in env) { From 8aa758e7b68597cf22493e9c0b1f0100a7c5cf03 Mon Sep 17 00:00:00 2001 From: silverwind Date: Tue, 26 Sep 2023 23:05:36 +0200 Subject: [PATCH 7/8] go back to old variable name --- docs/content/installation/from-source.en-us.md | 8 ++++---- docs/content/installation/from-source.zh-cn.md | 8 ++++---- webpack.config.js | 18 +++++++++--------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/docs/content/installation/from-source.en-us.md b/docs/content/installation/from-source.en-us.md index 3aec265463944..f6a95e8d0cfe8 100644 --- a/docs/content/installation/from-source.en-us.md +++ b/docs/content/installation/from-source.en-us.md @@ -261,8 +261,8 @@ make build ## Source Maps -By default, gitea generates reduced source maps for frontend files to conserve space. This can be controlled with the `SOURCEMAPS` environment variable: +By default, gitea generates reduced source maps for frontend files to conserve space. This can be controlled with the `ENABLE_SOURCEMAP` environment variable: -- `SOURCEMAPS=full` generates all source maps, the default for development builds -- `SOURCEMAPS=reduced` generates limited source maps, the default for production builds -- `SOURCEMAPS=none` generates no source maps +- `ENABLE_SOURCEMAP=true` generates all source maps, the default for development builds +- `ENABLE_SOURCEMAP=reduced` generates limited source maps, the default for production builds +- `ENABLE_SOURCEMAP=false` generates no source maps diff --git a/docs/content/installation/from-source.zh-cn.md b/docs/content/installation/from-source.zh-cn.md index 1b5e729c82bb8..74f76652db529 100644 --- a/docs/content/installation/from-source.zh-cn.md +++ b/docs/content/installation/from-source.zh-cn.md @@ -222,8 +222,8 @@ make build ## 源映射 -默认情况下,gitea 会为前端文件生成精简的源映射以节省空间。 这可以通过“SOURCEMAPS”环境变量进行控制: +默认情况下,gitea 会为前端文件生成精简的源映射以节省空间。 这可以通过“ENABLE_SOURCEMAP”环境变量进行控制: -- `SOURCEMAPS=full` 生成所有源映射,这是开发版本的默认设置 -- `SOURCEMAPS=reduced` 生成有限的源映射,这是生产版本的默认设置 -- `SOURCEMAPS=none` 不生成源映射 +- `ENABLE_SOURCEMAP=true` 生成所有源映射,这是开发版本的默认设置 +- `ENABLE_SOURCEMAP=reduced` 生成有限的源映射,这是生产版本的默认设置 +- `ENABLE_SOURCEMAP=false` 不生成源映射 diff --git a/webpack.config.js b/webpack.config.js index 0e9c0cfdb8aca..82a9987935a28 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -28,15 +28,15 @@ for (const path of glob('web_src/css/themes/*.css')) { const isProduction = env.NODE_ENV !== 'development'; -// SOURCEMAPS accepts the following values: -// "full" - all enabled, the default in development +// ENABLE_SOURCEMAP accepts the following values: +// "true" - all enabled, the default in development // "reduced" - minimal sourcemaps, the default in production -// "none" - all disabled +// "false" - all disabled let sourceMaps; -if ('SOURCEMAPS' in env) { - sourceMaps = ['none', 'full'].includes(env.SOURCEMAPS) ? env.SOURCEMAPS : 'reduced'; +if ('ENABLE_SOURCEMAP' in env) { + sourceMaps = ['true', 'false'].includes(env.ENABLE_SOURCEMAP) ? env.ENABLE_SOURCEMAP : 'reduced'; } else { - sourceMaps = isProduction ? 'reduced' : 'full'; + sourceMaps = isProduction ? 'reduced' : 'true'; } const filterCssImport = (url, ...args) => { @@ -110,7 +110,7 @@ export default { legalComments: 'none', }), LightningCssMinifyPlugin && new LightningCssMinifyPlugin({ - sourceMap: sourceMaps === 'full', + sourceMap: sourceMaps === 'true', }), ], splitChunks: { @@ -149,7 +149,7 @@ export default { { loader: 'css-loader', options: { - sourceMap: sourceMaps === 'full', + sourceMap: sourceMaps === 'true', url: {filter: filterCssImport}, import: {filter: filterCssImport}, }, @@ -187,7 +187,7 @@ export default { filename: 'css/[name].css', chunkFilename: 'css/[name].[contenthash:8].css', }), - sourceMaps !== 'none' && new SourceMapDevToolPlugin({ + sourceMaps !== 'false' && new SourceMapDevToolPlugin({ filename: '[file].[contenthash:8].map', ...(sourceMaps === 'reduced' && {include: /^js\/index\.js$/}), }), From 98bc1303704dd9964ef2d3ad77522faf85792d0e Mon Sep 17 00:00:00 2001 From: silverwind Date: Tue, 26 Sep 2023 23:22:11 +0200 Subject: [PATCH 8/8] comment tweak --- webpack.config.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/webpack.config.js b/webpack.config.js index 82a9987935a28..448dc640036c4 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -29,9 +29,9 @@ for (const path of glob('web_src/css/themes/*.css')) { const isProduction = env.NODE_ENV !== 'development'; // ENABLE_SOURCEMAP accepts the following values: -// "true" - all enabled, the default in development -// "reduced" - minimal sourcemaps, the default in production -// "false" - all disabled +// true - all enabled, the default in development +// reduced - minimal sourcemaps, the default in production +// false - all disabled let sourceMaps; if ('ENABLE_SOURCEMAP' in env) { sourceMaps = ['true', 'false'].includes(env.ENABLE_SOURCEMAP) ? env.ENABLE_SOURCEMAP : 'reduced';