summaryrefslogtreecommitdiffstats
path: root/webpack.config.js
diff options
context:
space:
mode:
authorsilverwind <me@silverwind.io>2023-08-11 06:13:25 +0200
committerGitHub <noreply@github.com>2023-08-11 06:13:25 +0200
commita838901a06d4c4339d82a8df826acd011073ca63 (patch)
treea5da9674b581b156b8727b094eb8f4361ee1ac99 /webpack.config.js
parent88479e0dfcbcb9ce229a72ead8c3c9c3b6bb04b0 (diff)
downloadgitea-a838901a06d4c4339d82a8df826acd011073ca63.tar.gz
gitea-a838901a06d4c4339d82a8df826acd011073ca63.zip
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>
Diffstat (limited to 'webpack.config.js')
-rw-r--r--webpack.config.js11
1 files 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',