Browse Source

Switches to swc for minification

- As fast as esbuild minification but with better results than terser
main
Eric Amodio 1 year ago
parent
commit
ae008255f3
3 changed files with 131 additions and 99 deletions
  1. +1
    -0
      package.json
  2. +57
    -99
      webpack.config.js
  3. +73
    -0
      yarn.lock

+ 1
- 0
package.json View File

@ -15809,6 +15809,7 @@
"sortablejs": "1.15.0"
},
"devDependencies": {
"@swc/core": "1.3.99",
"@twbs/fantasticon": "2.7.1",
"@types/mocha": "10.0.4",
"@types/node": "16.11.47",

+ 57
- 99
webpack.config.js View File

@ -9,7 +9,6 @@ const CopyPlugin = require('copy-webpack-plugin');
const CspHtmlPlugin = require('csp-html-webpack-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const esbuild = require('esbuild');
const { EsbuildPlugin } = require('esbuild-loader');
const { generateFonts } = require('@twbs/fantasticon');
const ForkTsCheckerPlugin = require('fork-ts-checker-webpack-plugin');
const fs = require('fs');
@ -24,7 +23,7 @@ const WebpackRequireFromPlugin = require('webpack-require-from');
module.exports =
/**
* @param {{ analyzeBundle?: boolean; analyzeDeps?: boolean; esbuild?: boolean; esbuildMinify?: boolean; useSharpForImageOptimization?: boolean } | undefined } env
* @param {{ analyzeBundle?: boolean; analyzeDeps?: boolean; esbuild?: boolean } | undefined } env
* @param {{ mode: 'production' | 'development' | 'none' | undefined }} argv
* @returns { WebpackConfig[] }
*/
@ -35,8 +34,6 @@ module.exports =
analyzeBundle: false,
analyzeDeps: false,
esbuild: true,
esbuildMinify: false,
useSharpForImageOptimization: true,
...env,
};
@ -50,7 +47,7 @@ module.exports =
/**
* @param { 'node' | 'webworker' } target
* @param { 'production' | 'development' | 'none' } mode
* @param {{ analyzeBundle?: boolean; analyzeDeps?: boolean; esbuild?: boolean; esbuildMinify?: boolean; useSharpForImageOptimization?: boolean }} env
* @param {{ analyzeBundle?: boolean; analyzeDeps?: boolean; esbuild?: boolean }} env
* @returns { WebpackConfig }
*/
function getExtensionConfig(target, mode, env) {
@ -159,36 +156,26 @@ function getExtensionConfig(target, mode, env) {
},
optimization: {
minimizer: [
env.esbuildMinify
? new EsbuildPlugin({
drop: ['debugger'],
format: 'cjs',
// Keep the class names otherwise @log won't provide a useful name
keepNames: true,
legalComments: 'none',
minify: true,
target: 'es2022',
treeShaking: true,
})
: new TerserPlugin({
extractComments: false,
parallel: true,
terserOptions: {
compress: {
drop_debugger: true,
ecma: 2020,
module: true,
},
ecma: 2020,
format: {
comments: false,
ecma: 2020,
},
// Keep the class names otherwise @log won't provide a useful name
keep_classnames: true,
module: true,
},
}),
new TerserPlugin({
minify: TerserPlugin.swcMinify,
extractComments: false,
parallel: true,
terserOptions: {
compress: {
drop_debugger: true,
ecma: 2020,
module: true,
},
ecma: 2020,
format: {
comments: false,
ecma: 2020,
},
// Keep the class names otherwise @log won't provide a useful name
keep_classnames: true,
module: true,
},
}),
],
splitChunks:
target === 'webworker'
@ -278,7 +265,7 @@ function getExtensionConfig(target, mode, env) {
/**
* @param { 'production' | 'development' | 'none' } mode
* @param {{ analyzeBundle?: boolean; analyzeDeps?: boolean; esbuild?: boolean; esbuildMinify?: boolean; useSharpForImageOptimization?: boolean }} env
* @param {{ analyzeBundle?: boolean; analyzeDeps?: boolean; esbuild?: boolean }} env
* @returns { WebpackConfig }
*/
function getWebviewsConfig(mode, env) {
@ -414,38 +401,27 @@ function getWebviewsConfig(mode, env) {
minimizer:
mode === 'production'
? [
env.esbuildMinify
? new EsbuildPlugin({
css: true,
drop: ['debugger', 'console'],
format: 'esm',
// Keep the class names otherwise @log won't provide a useful name
// keepNames: true,
legalComments: 'none',
minify: true,
target: 'es2022',
treeShaking: true,
})
: new TerserPlugin({
extractComments: false,
parallel: true,
terserOptions: {
compress: {
drop_debugger: true,
drop_console: true,
ecma: 2020,
module: true,
},
ecma: 2020,
format: {
comments: false,
ecma: 2020,
},
// // Keep the class names otherwise @log won't provide a useful name
// keep_classnames: true,
module: true,
},
}),
new TerserPlugin({
minify: TerserPlugin.swcMinify,
extractComments: false,
parallel: true,
terserOptions: {
compress: {
drop_debugger: true,
drop_console: true,
ecma: 2020,
module: true,
},
ecma: 2020,
format: {
comments: false,
ecma: 2020,
},
// // Keep the class names otherwise @log won't provide a useful name
// keep_classnames: true,
module: true,
},
}),
new ImageMinimizerPlugin({
deleteOriginalAssets: true,
generator: [imageGeneratorConfig],
@ -569,7 +545,7 @@ function getWebviewsConfig(mode, env) {
/**
* @param { 'production' | 'development' | 'none' } mode
* @param {{ analyzeBundle?: boolean; analyzeDeps?: boolean; esbuild?: boolean; useSharpForImageOptimization?: boolean } | undefined } env
* @param {{ analyzeBundle?: boolean; analyzeDeps?: boolean; esbuild?: boolean } | undefined } env
* @returns { CspHtmlPlugin }
*/
function getCspHtmlPlugin(mode, env) {
@ -609,48 +585,30 @@ function getCspHtmlPlugin(mode, env) {
/**
* @param { 'production' | 'development' | 'none' } mode
* @param {{ analyzeBundle?: boolean; analyzeDeps?: boolean; esbuild?: boolean; useSharpForImageOptimization?: boolean } | undefined } env
* @param {{ analyzeBundle?: boolean; analyzeDeps?: boolean; esbuild?: boolean } | undefined } env
* @returns { ImageMinimizerPlugin.Generator<any> }
*/
function getImageMinimizerConfig(mode, env) {
/** @type ImageMinimizerPlugin.Generator<any> */
// @ts-ignore
return env.useSharpForImageOptimization
? {
type: 'asset',
implementation: ImageMinimizerPlugin.sharpGenerate,
options: {
encodeOptions: {
webp: {
lossless: true,
},
},
},
}
: {
type: 'asset',
implementation: ImageMinimizerPlugin.imageminGenerate,
options: {
plugins: [
[
'imagemin-webp',
{
lossless: true,
nearLossless: 0,
quality: 100,
method: mode === 'production' ? 4 : 0,
},
],
],
return {
type: 'asset',
implementation: ImageMinimizerPlugin.sharpGenerate,
options: {
encodeOptions: {
webp: {
lossless: true,
},
};
},
},
};
}
/**
* @param { string } name
* @param { boolean } plus
* @param { 'production' | 'development' | 'none' } mode
* @param {{ analyzeBundle?: boolean; analyzeDeps?: boolean; esbuild?: boolean; useSharpForImageOptimization?: boolean } | undefined } env
* @param {{ analyzeBundle?: boolean; analyzeDeps?: boolean; esbuild?: boolean } | undefined } env
* @returns { HtmlPlugin }
*/
function getHtmlPlugin(name, plus, mode, env) {

+ 73
- 0
yarn.lock View File

@ -616,6 +616,79 @@
resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.27.8.tgz#6667fac16c436b5434a387a34dedb013198f6e6e"
integrity sha512-+Fj43pSMwJs4KRrH/938Uf+uAELIgVBmQzg/q1YG10djyfA3TnrU8N8XzqCh/okZdszqBQTZf96idMfE5lnwTA==
"@swc/core-darwin-arm64@1.3.99":
version "1.3.99"
resolved "https://registry.yarnpkg.com/@swc/core-darwin-arm64/-/core-darwin-arm64-1.3.99.tgz#def204349ac645b8de21a800fa784907642a6c91"
integrity sha512-Qj7Jct68q3ZKeuJrjPx7k8SxzWN6PqLh+VFxzA+KwLDpQDPzOlKRZwkIMzuFjLhITO4RHgSnXoDk/Syz0ZeN+Q==
"@swc/core-darwin-x64@1.3.99":
version "1.3.99"
resolved "https://registry.yarnpkg.com/@swc/core-darwin-x64/-/core-darwin-x64-1.3.99.tgz#2633f1ac1668ec569f34f86eb5250d56fcacd952"
integrity sha512-wR7m9QVJjgiBu1PSOHy7s66uJPa45Kf9bZExXUL+JAa9OQxt5y+XVzr+n+F045VXQOwdGWplgPnWjgbUUHEVyw==
"@swc/core-linux-arm64-gnu@1.3.99":
version "1.3.99"
resolved "https://registry.yarnpkg.com/@swc/core-linux-arm64-gnu/-/core-linux-arm64-gnu-1.3.99.tgz#871c2f049a3a5d88bcc7317ac004230517a08ba4"
integrity sha512-gcGv1l5t0DScEONmw5OhdVmEI/o49HCe9Ik38zzH0NtDkc+PDYaCcXU5rvfZP2qJFaAAr8cua8iJcOunOSLmnA==
"@swc/core-linux-arm64-musl@1.3.99":
version "1.3.99"
resolved "https://registry.yarnpkg.com/@swc/core-linux-arm64-musl/-/core-linux-arm64-musl-1.3.99.tgz#28ed1622e92bc13aab4b650f2af695af8695289b"
integrity sha512-XL1/eUsTO8BiKsWq9i3iWh7H99iPO61+9HYiWVKhSavknfj4Plbn+XyajDpxsauln5o8t+BRGitymtnAWJM4UQ==
"@swc/core-linux-x64-gnu@1.3.99":
version "1.3.99"
resolved "https://registry.yarnpkg.com/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.3.99.tgz#8e07add9cc8b76d542959e3240340effa6c6e446"
integrity sha512-fGrXYE6DbTfGNIGQmBefYxSk3rp/1lgbD0nVg4rl4mfFRQPi7CgGhrrqSuqZ/ezXInUIgoCyvYGWFSwjLXt/Qg==
"@swc/core-linux-x64-musl@1.3.99":
version "1.3.99"
resolved "https://registry.yarnpkg.com/@swc/core-linux-x64-musl/-/core-linux-x64-musl-1.3.99.tgz#677eb82d6862605cb0a81ec5b732bef2a9861b16"
integrity sha512-kvgZp/mqf3IJ806gUOL6gN6VU15+DfzM1Zv4Udn8GqgXiUAvbQehrtruid4Snn5pZTLj4PEpSCBbxgxK1jbssA==
"@swc/core-win32-arm64-msvc@1.3.99":
version "1.3.99"
resolved "https://registry.yarnpkg.com/@swc/core-win32-arm64-msvc/-/core-win32-arm64-msvc-1.3.99.tgz#6c9bf96dd4cb81b5960884906766dc47a49efb0d"
integrity sha512-yt8RtZ4W/QgFF+JUemOUQAkVW58cCST7mbfKFZ1v16w3pl3NcWd9OrtppFIXpbjU1rrUX2zp2R7HZZzZ2Zk/aQ==
"@swc/core-win32-ia32-msvc@1.3.99":
version "1.3.99"
resolved "https://registry.yarnpkg.com/@swc/core-win32-ia32-msvc/-/core-win32-ia32-msvc-1.3.99.tgz#6940a602b65137eee30f09ced7cd9fcb6e162b88"
integrity sha512-62p5fWnOJR/rlbmbUIpQEVRconICy5KDScWVuJg1v3GPLBrmacjphyHiJC1mp6dYvvoEWCk/77c/jcQwlXrDXw==
"@swc/core-win32-x64-msvc@1.3.99":
version "1.3.99"
resolved "https://registry.yarnpkg.com/@swc/core-win32-x64-msvc/-/core-win32-x64-msvc-1.3.99.tgz#7fcdfe6577f015604f7e69f71dda99822e946385"
integrity sha512-PdppWhkoS45VGdMBxvClVgF1hVjqamtvYd82Gab1i4IV45OSym2KinoDCKE1b6j3LwBLOn2J9fvChGSgGfDCHQ==
"@swc/core@1.3.99":
version "1.3.99"
resolved "https://registry.yarnpkg.com/@swc/core/-/core-1.3.99.tgz#24a2ff0aaa1096b31046c8099b043936db0c4ca6"
integrity sha512-8O996RfuPC4ieb4zbYMfbyCU9k4gSOpyCNnr7qBQ+o7IEmh8JCV6B8wwu+fT/Om/6Lp34KJe1IpJ/24axKS6TQ==
dependencies:
"@swc/counter" "^0.1.1"
"@swc/types" "^0.1.5"
optionalDependencies:
"@swc/core-darwin-arm64" "1.3.99"
"@swc/core-darwin-x64" "1.3.99"
"@swc/core-linux-arm64-gnu" "1.3.99"
"@swc/core-linux-arm64-musl" "1.3.99"
"@swc/core-linux-x64-gnu" "1.3.99"
"@swc/core-linux-x64-musl" "1.3.99"
"@swc/core-win32-arm64-msvc" "1.3.99"
"@swc/core-win32-ia32-msvc" "1.3.99"
"@swc/core-win32-x64-msvc" "1.3.99"
"@swc/counter@^0.1.1":
version "0.1.2"
resolved "https://registry.yarnpkg.com/@swc/counter/-/counter-0.1.2.tgz#bf06d0770e47c6f1102270b744e17b934586985e"
integrity sha512-9F4ys4C74eSTEUNndnER3VJ15oru2NumfQxS8geE+f3eB5xvfxpWyqE5XlVnxb/R14uoXi6SLbBwwiDSkv+XEw==
"@swc/types@^0.1.5":
version "0.1.5"
resolved "https://registry.yarnpkg.com/@swc/types/-/types-0.1.5.tgz#043b731d4f56a79b4897a3de1af35e75d56bc63a"
integrity sha512-myfUej5naTBWnqOCc/MdVOLVjXUXtIA+NpDrDBKJtLLg2shUjBu3cZmB/85RyitKc55+lUUyl7oRfLOvkr2hsw==
"@tootallnate/once@1":
version "1.1.2"
resolved "https://registry.yarnpkg.com/@tootallnate/once/-/once-1.1.2.tgz#ccb91445360179a04e7fe6aff78c00ffc1eeaf82"

Loading…
Cancel
Save