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

Fall back to esbuild for css minify #26445

Merged
merged 2 commits into from
Aug 11, 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
11 changes: 8 additions & 3 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down