From a838901a06d4c4339d82a8df826acd011073ca63 Mon Sep 17 00:00:00 2001 From: silverwind Date: Fri, 11 Aug 2023 06:13:25 +0200 Subject: [PATCH] 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 --- webpack.config.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/webpack.config.js b/webpack.config.js index 69d803b1e2..9574961116 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -11,7 +11,6 @@ import webpack from 'webpack'; import {fileURLToPath} from 'node:url'; import {readFileSync} from 'node:fs'; import {env} from 'node:process'; -import {LightningCssMinifyPlugin} from 'lightningcss-loader'; const {EsbuildPlugin} = EsBuildLoader; const {SourceMapDevToolPlugin, DefinePlugin} = webpack; @@ -52,6 +51,12 @@ const filterCssImport = (url, ...args) => { 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} */ export default { mode: isProduction ? 'production' : 'development', @@ -97,10 +102,10 @@ export default { new EsbuildPlugin({ target: 'es2015', minify: true, - css: false, + css: !LightningCssMinifyPlugin, legalComments: 'none', }), - new LightningCssMinifyPlugin(), + LightningCssMinifyPlugin && new LightningCssMinifyPlugin(), ], splitChunks: { chunks: 'async',