Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable all webpack sourcemaps in dev build, disable all in prod build #25089

Merged
merged 5 commits into from
Jun 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/content/doc/installation/from-source.en-us.md
Original file line number Diff line number Diff line change
@@ -132,6 +132,8 @@ 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.

## Test

After following the steps above, a `gitea` binary will be available in the working directory.
22 changes: 13 additions & 9 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ import {parse, dirname} from 'node:path';
import webpack from 'webpack';
import {fileURLToPath} from 'node:url';
import {readFileSync} from 'node:fs';
import {env} from 'node:process';

const {EsbuildPlugin} = EsBuildLoader;
const {SourceMapDevToolPlugin, DefinePlugin} = webpack;
@@ -25,7 +26,14 @@ for (const path of glob('web_src/css/themes/*.css')) {
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 cssFile = args[1] || args[0]; // resourcePath is 2nd argument for url and 3rd for import
@@ -122,7 +130,7 @@ export default {
{
loader: 'css-loader',
options: {
sourceMap: true,
sourceMap: sourceMapEnabled,
url: {filter: filterCssImport},
import: {filter: filterCssImport},
},
@@ -160,13 +168,9 @@ export default {
filename: 'css/[name].css',
chunkFilename: 'css/[name].[contenthash:8].css',
}),
new SourceMapDevToolPlugin({
sourceMapEnabled && (new SourceMapDevToolPlugin({
filename: '[file].[contenthash:8].map',
include: [
'js/index.js',
'css/index.css',
],
}),
})),
new MonacoWebpackPlugin({
filename: 'js/monaco-[name].[contenthash:8].worker.js',
}),
@@ -195,7 +199,7 @@ export default {
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)',
}) : new AddAssetPlugin('js/licenses.txt', `Licenses are disabled during development`),
],
].filter(Boolean),
performance: {
hints: false,
maxEntrypointSize: Infinity,