Browse Source

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
https://github.com/go-gitea/gitea/issues/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.
tags/v1.20.0-rc0
silverwind 1 year ago
parent
commit
c09f747b51
No account linked to committer's email address
2 changed files with 15 additions and 9 deletions
  1. 2
    0
      docs/content/doc/installation/from-source.en-us.md
  2. 13
    9
      webpack.config.js

+ 2
- 0
docs/content/doc/installation/from-source.en-us.md View File

TAGS="bindata" make 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.

## Test ## Test


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

+ 13
- 9
webpack.config.js View File

import webpack from 'webpack'; import webpack from 'webpack';
import {fileURLToPath} from 'node:url'; import {fileURLToPath} from 'node:url';
import {readFileSync} from 'node:fs'; import {readFileSync} from 'node:fs';
import {env} from 'node:process';


const {EsbuildPlugin} = EsBuildLoader; const {EsbuildPlugin} = EsBuildLoader;
const {SourceMapDevToolPlugin, DefinePlugin} = webpack; const {SourceMapDevToolPlugin, DefinePlugin} = webpack;
themes[parse(path).name] = [path]; themes[parse(path).name] = [path];
} }


const isProduction = process.env.NODE_ENV !== 'development';
const isProduction = env.NODE_ENV !== 'development';

let sourceMapEnabled;
if ('ENABLE_SOURCEMAP' in env) {
sourceMapEnabled = env.ENABLE_SOURCEMAP === 'true';
} else {
sourceMapEnabled = !isProduction;
}


const filterCssImport = (url, ...args) => { const filterCssImport = (url, ...args) => {
const cssFile = args[1] || args[0]; // resourcePath is 2nd argument for url and 3rd for import const cssFile = args[1] || args[0]; // resourcePath is 2nd argument for url and 3rd for import
{ {
loader: 'css-loader', loader: 'css-loader',
options: { options: {
sourceMap: true,
sourceMap: sourceMapEnabled,
url: {filter: filterCssImport}, url: {filter: filterCssImport},
import: {filter: filterCssImport}, import: {filter: filterCssImport},
}, },
filename: 'css/[name].css', filename: 'css/[name].css',
chunkFilename: 'css/[name].[contenthash:8].css', chunkFilename: 'css/[name].[contenthash:8].css',
}), }),
new SourceMapDevToolPlugin({
sourceMapEnabled && (new SourceMapDevToolPlugin({
filename: '[file].[contenthash:8].map', filename: '[file].[contenthash:8].map',
include: [
'js/index.js',
'css/index.css',
],
}),
})),
new MonacoWebpackPlugin({ new MonacoWebpackPlugin({
filename: 'js/monaco-[name].[contenthash:8].worker.js', filename: 'js/monaco-[name].[contenthash:8].worker.js',
}), }),
emitError: true, emitError: true,
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)', 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)',
}) : new AddAssetPlugin('js/licenses.txt', `Licenses are disabled during development`), }) : new AddAssetPlugin('js/licenses.txt', `Licenses are disabled during development`),
],
].filter(Boolean),
performance: { performance: {
hints: false, hints: false,
maxEntrypointSize: Infinity, maxEntrypointSize: Infinity,

Loading…
Cancel
Save