From 41c86d1cf111b20c130688ef26a418a92b978f64 Mon Sep 17 00:00:00 2001 From: David Mehren Date: Wed, 5 May 2021 13:37:47 +0200 Subject: [PATCH] Use esbuild to minify frontend JS This speeds up build times massively Signed-off-by: David Mehren --- .babelrc | 3 +-- package.json | 1 + webpack.prod.js | 10 +++++++++- yarn.lock | 45 +++++++++++++++++++++++++++++++++++++-------- 4 files changed, 48 insertions(+), 11 deletions(-) diff --git a/.babelrc b/.babelrc index ad37aa757..6f316280e 100644 --- a/.babelrc +++ b/.babelrc @@ -2,8 +2,7 @@ "presets": [ ["env", { "targets": { - "node": "8", - "uglify": true + "browsers": "defaults" } }] ], diff --git a/package.json b/package.json index a558a4dcd..60a43d57b 100644 --- a/package.json +++ b/package.json @@ -151,6 +151,7 @@ "copy-webpack-plugin": "6.4.1", "css-loader": "5.2.4", "emojify.js": "^1.1.0", + "esbuild-loader": "2.13.0", "escape-html": "^1.0.3", "eslint": "7.25.0", "eslint-config-standard": "16.0.2", diff --git a/webpack.prod.js b/webpack.prod.js index 5c523c065..92ee1578b 100644 --- a/webpack.prod.js +++ b/webpack.prod.js @@ -1,8 +1,9 @@ const common = require('./webpack.common.js') const htmlexport = require('./webpack.htmlexport') -const { merge } = require('webpack-merge'); +const { merge } = require('webpack-merge') const path = require('path') const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin') +const { ESBuildMinifyPlugin } = require('esbuild-loader') module.exports = [ merge(common, { @@ -11,6 +12,13 @@ module.exports = [ path: path.join(__dirname, 'public/build'), publicPath: 'build/', filename: '[name].[contenthash].js' + }, + optimization: { + minimizer: [ + new ESBuildMinifyPlugin({ + target: 'es2015' + }) + ] } }), merge(htmlexport, { diff --git a/yarn.lock b/yarn.lock index e7c464b5b..1cce83cd9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -568,7 +568,6 @@ "Idle.Js@git+https://github.com/shawnmclean/Idle.js": version "0.0.1" - uid db9beb3483a460ad638ec947867720f0ed066a62 resolved "git+https://github.com/shawnmclean/Idle.js#db9beb3483a460ad638ec947867720f0ed066a62" JSV@^4.0.x: @@ -2311,7 +2310,6 @@ code-point-at@^1.0.0: "codemirror@git+https://github.com/hedgedoc/CodeMirror.git": version "5.58.2" - uid f780b569b3717cdff4c8507538cc63101bfa02e1 resolved "git+https://github.com/hedgedoc/CodeMirror.git#f780b569b3717cdff4c8507538cc63101bfa02e1" collection-visit@^1.0.0: @@ -3342,7 +3340,6 @@ detect-libc@^1.0.2: "diff-match-patch@git+https://github.com/hackmdio/diff-match-patch.git": version "1.1.1" - uid c2f8fb9d69aa9490b764850aa86ba442c93ccf78 resolved "git+https://github.com/hackmdio/diff-match-patch.git#c2f8fb9d69aa9490b764850aa86ba442c93ccf78" diff@5.0.0: @@ -3701,6 +3698,23 @@ es6-error@^4.1.1: resolved "https://registry.yarnpkg.com/es6-error/-/es6-error-4.1.1.tgz#9e3af407459deed47e9a91f9b885a84eb05c561d" integrity sha512-Um/+FxMr9CISWh0bi5Zv0iOD+4cFh5qLeks1qhAopKVAJw3drgKbKySikp7wGhDL0HPeaja0P5ULZrxLkniUVg== +esbuild-loader@2.13.0: + version "2.13.0" + resolved "https://registry.yarnpkg.com/esbuild-loader/-/esbuild-loader-2.13.0.tgz#f5a3602a89a3b728506ae3e1887304fffeef9270" + integrity sha512-gC9lML8RGkTSWG2pJVEOZRLMoIluq1Jd7OzzVkOZKMzbMDMWDhXEwXLs60n+aglnAYa9GVrD/UXjTHkM51nBsg== + dependencies: + esbuild "^0.11.19" + joycon "^3.0.1" + json5 "^2.2.0" + loader-utils "^2.0.0" + type-fest "^1.0.1" + webpack-sources "^2.2.0" + +esbuild@^0.11.19: + version "0.11.19" + resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.11.19.tgz#59289d9c6ee3f45d0db289a662c31473da25c199" + integrity sha512-X2h8UThAwKLxmc1OChHVegIScphS/qU9cUB5vCEV2T0A024E8Ptpg9xssXXcs+j1uEgXrDJZuVRzx2JsmGzq7A== + escalade@^3.1.1: version "3.1.1" resolved "https://registry.yarnpkg.com/escalade/-/escalade-3.1.1.tgz#d8cfdc7000965c5a0174b4a82eaa5c0552742e40" @@ -5613,6 +5627,11 @@ jmespath@0.15.0: resolved "https://registry.yarnpkg.com/jmespath/-/jmespath-0.15.0.tgz#a3f222a9aae9f966f5d27c796510e28091764217" integrity sha1-o/Iiqarp+Wb10nx5ZRDigJF2Qhc= +joycon@^3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/joycon/-/joycon-3.0.1.tgz#9074c9b08ccf37a6726ff74a18485f85efcaddaf" + integrity sha512-SJcJNBg32dGgxhPtM0wQqxqV0ax9k/9TaUskGDSJkSFSQOEWWvQ3zzWdGQRIUry2j1zA5+ReH13t0Mf3StuVZA== + jquery-mousewheel@^3.1.13: version "3.1.13" resolved "https://registry.yarnpkg.com/jquery-mousewheel/-/jquery-mousewheel-3.1.13.tgz#06f0335f16e353a695e7206bf50503cb523a6ee5" @@ -5635,7 +5654,6 @@ js-cookie@^2.1.3: "js-sequence-diagrams@git+https://github.com/hedgedoc/js-sequence-diagrams.git": version "2.0.1" - uid bda0e49b6c2754f3c7158b1dfb9ccf26efc24b39 resolved "git+https://github.com/hedgedoc/js-sequence-diagrams.git#bda0e49b6c2754f3c7158b1dfb9ccf26efc24b39" dependencies: lodash "4.17.x" @@ -5767,7 +5785,7 @@ json5@^1.0.1: dependencies: minimist "^1.2.0" -json5@^2.0.0, json5@^2.1.2: +json5@^2.0.0, json5@^2.1.2, json5@^2.2.0: version "2.2.0" resolved "https://registry.yarnpkg.com/json5/-/json5-2.2.0.tgz#2dfefe720c6ba525d9ebd909950f0515316c89a3" integrity sha512-f+8cldu7X/y7RAJurMEJmdoKXGB/X550w2Nr3tTbezL6RwEE/iMcm+tZnXeoZtKuOq6ft8+CqzEkrIgx1fPoQA== @@ -6221,7 +6239,6 @@ lutim@^1.0.2: "lz-string@git+https://github.com/hackmdio/lz-string.git": version "1.4.4" - uid efd1f64676264d6d8871b01f4f375fc6ef4f9022 resolved "git+https://github.com/hackmdio/lz-string.git#efd1f64676264d6d8871b01f4f375fc6ef4f9022" make-dir@^1.0.0: @@ -6535,7 +6552,6 @@ messageformat@^2.3.0: "meta-marked@git+https://github.com/hedgedoc/meta-marked": version "0.4.5" - uid "3002adae670a6de0a845f3da7a7223d458c20d76" resolved "git+https://github.com/hedgedoc/meta-marked#3002adae670a6de0a845f3da7a7223d458c20d76" dependencies: js-yaml "~4.1.0" @@ -9783,7 +9799,7 @@ socket.io@^2.1.1: socket.io-client "2.4.0" socket.io-parser "~3.4.0" -source-list-map@^2.0.0: +source-list-map@^2.0.0, source-list-map@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/source-list-map/-/source-list-map-2.0.1.tgz#3993bd873bfc48479cca9ea3a547835c7c154b34" integrity sha512-qnQ7gVMxGNxsiL4lEuJwe/To8UnK7fAnmbGEEH8RpLouuKbeEm0lhbQVFIrNSuB+G7tVrAlVsZgETT5nljf+Iw== @@ -10543,6 +10559,11 @@ type-fest@^0.8.1: resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.8.1.tgz#09e249ebde851d3b1e48d27c105444667f17b83d" integrity sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA== +type-fest@^1.0.1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-1.0.2.tgz#3f9c39982859f385c77c38b7e5f1432b8a3661c6" + integrity sha512-a720oz3Kjbp3ll0zkeN9qjRhO7I34MKMhPGQiQJAmaZQZQ1lo+NWThK322f7sXV+kTg9B1Ybt16KgBXWgteT8w== + type-is@~1.6.17, type-is@~1.6.18: version "1.6.18" resolved "https://registry.yarnpkg.com/type-is/-/type-is-1.6.18.tgz#4e552cd05df09467dcbc4ef739de89f2cf37c131" @@ -11095,6 +11116,14 @@ webpack-sources@^1.1.0, webpack-sources@^1.4.0, webpack-sources@^1.4.1, webpack- source-list-map "^2.0.0" source-map "~0.6.1" +webpack-sources@^2.2.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-2.2.0.tgz#058926f39e3d443193b6c31547229806ffd02bac" + integrity sha512-bQsA24JLwcnWGArOKUxYKhX3Mz/nK1Xf6hxullKERyktjNMC4x8koOeaDNTA2fEJ09BdWLbM/iTW0ithREUP0w== + dependencies: + source-list-map "^2.0.1" + source-map "^0.6.1" + webpack@4.46.0: version "4.46.0" resolved "https://registry.yarnpkg.com/webpack/-/webpack-4.46.0.tgz#bf9b4404ea20a073605e0a011d188d77cb6ad542"