forked from forgejo/forgejo
Backport #27291 by @silverwind 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 https://github.com/go-gitea/gitea/issues/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. The chinese docs are machine-translated, please correct accordingly. Co-authored-by: silverwind <me@silverwind.io>
This commit is contained in:
parent
fee8522052
commit
42f7c2ad89
3 changed files with 30 additions and 11 deletions
|
@ -28,11 +28,15 @@ for (const path of glob('web_src/css/themes/*.css')) {
|
|||
|
||||
const isProduction = env.NODE_ENV !== 'development';
|
||||
|
||||
let sourceMapEnabled;
|
||||
// ENABLE_SOURCEMAP accepts the following values:
|
||||
// true - all enabled, the default in development
|
||||
// reduced - minimal sourcemaps, the default in production
|
||||
// false - all disabled
|
||||
let sourceMaps;
|
||||
if ('ENABLE_SOURCEMAP' in env) {
|
||||
sourceMapEnabled = env.ENABLE_SOURCEMAP === 'true';
|
||||
sourceMaps = ['true', 'false'].includes(env.ENABLE_SOURCEMAP) ? env.ENABLE_SOURCEMAP : 'reduced';
|
||||
} else {
|
||||
sourceMapEnabled = !isProduction;
|
||||
sourceMaps = isProduction ? 'reduced' : 'true';
|
||||
}
|
||||
|
||||
const filterCssImport = (url, ...args) => {
|
||||
|
@ -105,7 +109,9 @@ export default {
|
|||
css: !LightningCssMinifyPlugin,
|
||||
legalComments: 'none',
|
||||
}),
|
||||
LightningCssMinifyPlugin && new LightningCssMinifyPlugin(),
|
||||
LightningCssMinifyPlugin && new LightningCssMinifyPlugin({
|
||||
sourceMap: sourceMaps === 'true',
|
||||
}),
|
||||
],
|
||||
splitChunks: {
|
||||
chunks: 'async',
|
||||
|
@ -143,7 +149,7 @@ export default {
|
|||
{
|
||||
loader: 'css-loader',
|
||||
options: {
|
||||
sourceMap: sourceMapEnabled,
|
||||
sourceMap: sourceMaps === 'true',
|
||||
url: {filter: filterCssImport},
|
||||
import: {filter: filterCssImport},
|
||||
},
|
||||
|
@ -181,9 +187,10 @@ export default {
|
|||
filename: 'css/[name].css',
|
||||
chunkFilename: 'css/[name].[contenthash:8].css',
|
||||
}),
|
||||
sourceMapEnabled && (new SourceMapDevToolPlugin({
|
||||
sourceMaps !== 'false' && new SourceMapDevToolPlugin({
|
||||
filename: '[file].[contenthash:8].map',
|
||||
})),
|
||||
...(sourceMaps === 'reduced' && {include: /^js\/index\.js$/}),
|
||||
}),
|
||||
new MonacoWebpackPlugin({
|
||||
filename: 'js/monaco-[name].[contenthash:8].worker.js',
|
||||
}),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue