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

feat(client): allow to pass terser options #126

Merged
merged 1 commit into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ With this `{rootDir}/src/ui/tsconfig.json`:
- `locale`: (`string[]=['ru']`) — list of `moment.js` or `day.js` locales to include, e.g. `['de', 'es']`. Locale `En` is always present.
- `safari10` (`boolean`) — Enables `safari10` terser's option. [Terser options](https://github.com/terser/terser#minify-options)
- `transformCssWithLightningCss` (`boolean`) — use [Lighting CSS](https://lightningcss.dev) to transform and minimize css instead of PostCSS and cssnano
- `terser` (`(options: TerserOptions) => TerserOptions`) - modify or return a custom [Terser options](https://github.com/terser/terser#minify-options).

##### Monaco editor support

Expand Down
7 changes: 7 additions & 0 deletions src/common/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type {Options as StatoscopeOptions} from '@statoscope/webpack-plugin';
import type {SentryWebpackPluginOptions} from '@sentry/webpack-plugin';
import type {WebpackMode} from '../webpack/config';
import type {UploadOptions} from '../s3-upload/upload';
import type {TerserOptions} from 'terser-webpack-plugin';

export interface Entities<T> {
data: Record<string, T>;
Expand Down Expand Up @@ -134,6 +135,8 @@ export interface ClientConfig {
symlinks?: boolean;
/**
* Enables `safari10` terser's option. [Terser options](https://github.com/terser/terser#minify-options)
*
* @deprecated use `terser` option instead
*/
safari10?: boolean;
/**
Expand Down Expand Up @@ -201,6 +204,10 @@ export interface ClientConfig {
config: Babel.TransformOptions,
options: {configType: `${WebpackMode}`},
) => Babel.TransformOptions | Promise<Babel.TransformOptions>;
/**
* Modify or return a custom [Terser options](https://github.com/terser/terser#minify-options).
*/
terser?: (options: TerserOptions) => TerserOptions;
}

export interface CdnUploadConfig {
Expand Down
19 changes: 11 additions & 8 deletions src/common/webpack/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -968,15 +968,18 @@ function configureOptimization({config}: HelperOptions): webpack.Configuration['
(compiler) => {
// Lazy load the Terser plugin
const TerserPlugin: typeof TerserWebpackPlugin = require('terser-webpack-plugin');
new TerserPlugin({
terserOptions: {
compress: {
passes: 2,
},
safari10: config.safari10,
mangle: !config.reactProfiling,
let terserOptions: TerserWebpackPlugin.TerserOptions = {
compress: {
passes: 2,
},
}).apply(compiler);
safari10: config.safari10,
mangle: !config.reactProfiling,
};
const {terser} = config;
if (typeof terser === 'function') {
terserOptions = terser(terserOptions);
}
new TerserPlugin({terserOptions}).apply(compiler);
},
],
};
Expand Down
Loading