mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-23 14:53:34 +01:00
Fall back to esbuild for css minify (#26445)
Fixes https://github.com/go-gitea/gitea/issues/26439. The minification result is not ideal with esbuild, but it's better than failing competely. Co-authored-by: Giteabot <teabot@gitea.io>
This commit is contained in:
parent
88479e0dfc
commit
a838901a06
1 changed files with 8 additions and 3 deletions
|
@ -11,7 +11,6 @@ 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';
|
import {env} from 'node:process';
|
||||||
import {LightningCssMinifyPlugin} from 'lightningcss-loader';
|
|
||||||
|
|
||||||
const {EsbuildPlugin} = EsBuildLoader;
|
const {EsbuildPlugin} = EsBuildLoader;
|
||||||
const {SourceMapDevToolPlugin, DefinePlugin} = webpack;
|
const {SourceMapDevToolPlugin, DefinePlugin} = webpack;
|
||||||
|
@ -52,6 +51,12 @@ const filterCssImport = (url, ...args) => {
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// in case lightningcss fails to load, fall back to esbuild for css minify
|
||||||
|
let LightningCssMinifyPlugin;
|
||||||
|
try {
|
||||||
|
({LightningCssMinifyPlugin} = await import('lightningcss-loader'));
|
||||||
|
} catch {}
|
||||||
|
|
||||||
/** @type {import("webpack").Configuration} */
|
/** @type {import("webpack").Configuration} */
|
||||||
export default {
|
export default {
|
||||||
mode: isProduction ? 'production' : 'development',
|
mode: isProduction ? 'production' : 'development',
|
||||||
|
@ -97,10 +102,10 @@ export default {
|
||||||
new EsbuildPlugin({
|
new EsbuildPlugin({
|
||||||
target: 'es2015',
|
target: 'es2015',
|
||||||
minify: true,
|
minify: true,
|
||||||
css: false,
|
css: !LightningCssMinifyPlugin,
|
||||||
legalComments: 'none',
|
legalComments: 'none',
|
||||||
}),
|
}),
|
||||||
new LightningCssMinifyPlugin(),
|
LightningCssMinifyPlugin && new LightningCssMinifyPlugin(),
|
||||||
],
|
],
|
||||||
splitChunks: {
|
splitChunks: {
|
||||||
chunks: 'async',
|
chunks: 'async',
|
||||||
|
|
Loading…
Reference in a new issue