From 3af141c371aa6f1b28089f0970e3ed9d9a74f84b Mon Sep 17 00:00:00 2001 From: Kainoa Kanter Date: Tue, 3 Oct 2023 07:53:53 +0000 Subject: [PATCH] build: :zap: build service worker with Vite instead of Webpack --- packages/client/vite.config.ts | 2 +- packages/sw/package.json | 10 +- packages/sw/vite.config.ts | 42 ++++++ packages/sw/webpack.config.js | 50 ------- pnpm-lock.yaml | 230 +++------------------------------ 5 files changed, 65 insertions(+), 269 deletions(-) create mode 100644 packages/sw/vite.config.ts delete mode 100644 packages/sw/webpack.config.js diff --git a/packages/client/vite.config.ts b/packages/client/vite.config.ts index 90f75b66c..ad9dc2c23 100644 --- a/packages/client/vite.config.ts +++ b/packages/client/vite.config.ts @@ -60,7 +60,7 @@ export default defineConfig(({ command, mode }) => { ), _ENV_: JSON.stringify(process.env.NODE_ENV), _DEV_: process.env.NODE_ENV !== "production", - _PERF_PREFIX_: JSON.stringify("Misskey:"), + _PERF_PREFIX_: JSON.stringify("Firefish:"), _DATA_TRANSFER_DRIVE_FILE_: JSON.stringify("mk_drive_file"), _DATA_TRANSFER_DRIVE_FOLDER_: JSON.stringify("mk_drive_folder"), _DATA_TRANSFER_DECK_COLUMN_: JSON.stringify("mk_deck_column"), diff --git a/packages/sw/package.json b/packages/sw/package.json index aa86e4c0a..d92cfd5e8 100644 --- a/packages/sw/package.json +++ b/packages/sw/package.json @@ -2,7 +2,7 @@ "name": "sw", "private": true, "scripts": { - "build": "webpack", + "build": "pnpm vite build --emptyOutDir", "build:debug": "pnpm run build", "watch": "pnpm swc src -d built -D -w", "lint": "pnpm biome check **/*.ts --apply", @@ -14,8 +14,10 @@ "@swc/core-android-arm64": "1.3.11", "firefish-js": "workspace:*", "idb-keyval": "^6.2.1", - "swc-loader": "^0.2.3", - "webpack": "^5.85.1", - "webpack-cli": "^5.1.3" + "vite": "4.4.9", + "vite-plugin-compression": "^0.5.1" + }, + "optionalDependencies": { + "@swc/core-android-arm64": "1.3.11" } } diff --git a/packages/sw/vite.config.ts b/packages/sw/vite.config.ts new file mode 100644 index 000000000..235ae1d6e --- /dev/null +++ b/packages/sw/vite.config.ts @@ -0,0 +1,42 @@ +import { defineConfig } from "vite"; +const locales = require("../../locales"); +const meta = require("../../package.json"); + +const isProduction = process.env.NODE_ENV === "production"; +import viteCompression from "vite-plugin-compression"; + +export default defineConfig({ + mode: isProduction ? "production" : "development", + build: { + target: "modules", + outDir: "../../built/_sw_dist_", + assetsDir: "", + rollupOptions: { + input: "./src/sw.ts", + output: { + entryFileNames: "sw.js", + }, + }, + }, + resolve: { + alias: { + "@/": `${__dirname}/src/`, + }, + extensions: [".js", ".ts"], + }, + define: { + _VERSION_: JSON.stringify(meta.version), + _LANGS_: JSON.stringify( + Object.entries(locales).map(([k, v]) => [k, v._lang_]), + ), + _ENV_: JSON.stringify(process.env.NODE_ENV), + _DEV_: !isProduction, + _PERF_PREFIX_: JSON.stringify("Firefish:"), + }, + plugins: [ + viteCompression({ + algorithm: "brotliCompress", + verbose: false, + }), + ], +}); diff --git a/packages/sw/webpack.config.js b/packages/sw/webpack.config.js deleted file mode 100644 index 5df254409..000000000 --- a/packages/sw/webpack.config.js +++ /dev/null @@ -1,50 +0,0 @@ -const webpack = require("webpack"); -const path = require("path"); -const locales = require("../../locales"); -const meta = require("../../package.json"); - -const isProduction = process.env.NODE_ENV === "production"; - -module.exports = { - mode: isProduction ? "production" : "development", - stats: "errors-only", - entry: "./src/sw.ts", - output: { - path: path.resolve(__dirname, "../../built/_sw_dist_"), - filename: "sw.js", - }, - resolve: { - extensions: [".js", ".ts"], - }, - module: { - rules: [ - { - test: /\.ts$/, - exclude: /(node_modules|bower_components)/, - use: { - loader: "swc-loader", - options: { - // This makes swc-loader invoke swc synchronously. - sync: true, - jsc: { - parser: { - syntax: "typescript", - }, - }, - }, - }, - }, - ], - }, - plugins: [ - new webpack.DefinePlugin({ - _VERSION_: JSON.stringify(meta.version), - _LANGS_: JSON.stringify( - Object.entries(locales).map(([k, v]) => [k, v._lang_]), - ), - _ENV_: JSON.stringify(process.env.NODE_ENV), - _DEV_: !isProduction, - _PERF_PREFIX_: JSON.stringify("Firefish:"), - }), - ], -}; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8af64adbf..6bb5a0e0f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1069,6 +1069,10 @@ importers: version: 0.23.24(typescript@4.9.4) packages/sw: + optionalDependencies: + '@swc/core-android-arm64': + specifier: 1.3.11 + version: 1.3.11 devDependencies: '@swc/cli': specifier: ^0.1.62 @@ -1076,24 +1080,18 @@ importers: '@swc/core': specifier: 1.3.78 version: 1.3.78 - '@swc/core-android-arm64': - specifier: 1.3.11 - version: 1.3.11 firefish-js: specifier: workspace:* version: link:../firefish-js idb-keyval: specifier: ^6.2.1 version: 6.2.1 - swc-loader: - specifier: ^0.2.3 - version: 0.2.3(@swc/core@1.3.78)(webpack@5.88.1) - webpack: - specifier: ^5.85.1 - version: 5.88.1(@swc/core@1.3.78)(webpack-cli@5.1.3) - webpack-cli: - specifier: ^5.1.3 - version: 5.1.3(webpack@5.88.1) + vite: + specifier: 4.4.9 + version: 4.4.9(@types/node@20.5.8)(sass@1.66.1) + vite-plugin-compression: + specifier: ^0.5.1 + version: 0.5.1(vite@4.4.9) packages: @@ -1816,11 +1814,6 @@ packages: twemoji-parser: 14.0.0 universalify: 0.1.2 - /@discoveryjs/json-ext@0.5.7: - resolution: {integrity: sha512-dBVuXR082gk3jsFp7Rd/JI4kytwGHecnCoTtXFb7DB6CNHp4rg5k1bhg0nWdLGLnOV71lmDzGQaLMy8iPLY0pw==} - engines: {node: '>=10.0.0'} - dev: true - /@elastic/elasticsearch@7.17.0: resolution: {integrity: sha512-5QLPCjd0uLmLj1lSuKSThjNpq39f6NmlTy9ROLFwG5gjyTgpwSqufDeYG/Fm43Xs05uF7WcscoO7eguI3HuuYA==} engines: {node: '>=12'} @@ -3313,8 +3306,11 @@ packages: engines: {node: '>=10'} cpu: [arm64] os: [android] + requiresBuild: true dependencies: '@swc/wasm': 1.2.130 + dev: false + optional: true /@swc/core-darwin-arm64@1.3.78: resolution: {integrity: sha512-596KRua/d5Gx1buHKKchSyHuwoIL4S1BRD/wCvYNLNZ3xOzcuBBmXOjrDVigKi1ztNDeS07p30RO5UyYur0XAA==} @@ -3419,6 +3415,9 @@ packages: /@swc/wasm@1.2.130: resolution: {integrity: sha512-rNcJsBxS70+pv8YUWwf5fRlWX6JoY/HJc25HD/F8m6Kv7XhJdqPPMhyX6TKkUBPAG7TWlZYoxa+rHAjPy4Cj3Q==} + requiresBuild: true + dev: false + optional: true /@syuilo/aiscript@0.11.1: resolution: {integrity: sha512-chwOIA3yLUKvOB0G611hjLArKTeOWNmTm3lHERSaDW1d+dS6do56naX6Lkwy2UpnwWC0qzeNSgg35elk6t2gZg==} @@ -5117,43 +5116,6 @@ packages: resolution: {integrity: sha512-9AXJSmL3MzY8ZL//JjudA//q+2kBRGhLBFpkdGksWIuxrMy81nFrCzj2Am+mbh8WoU6rXmv7cY5E3rdlyru2Qg==} dev: false - /@webpack-cli/configtest@2.1.1(webpack-cli@5.1.3)(webpack@5.88.1): - resolution: {integrity: sha512-wy0mglZpDSiSS0XHrVR+BAdId2+yxPSoJW8fsna3ZpYSlufjvxnP4YbKTCBZnNIcGN4r6ZPXV55X4mYExOfLmw==} - engines: {node: '>=14.15.0'} - peerDependencies: - webpack: 5.x.x - webpack-cli: 5.x.x - dependencies: - webpack: 5.88.1(@swc/core@1.3.78)(webpack-cli@5.1.3) - webpack-cli: 5.1.3(webpack@5.88.1) - dev: true - - /@webpack-cli/info@2.0.2(webpack-cli@5.1.3)(webpack@5.88.1): - resolution: {integrity: sha512-zLHQdI/Qs1UyT5UBdWNqsARasIA+AaF8t+4u2aS2nEpBQh2mWIVb8qAklq0eUENnC5mOItrIB4LiS9xMtph18A==} - engines: {node: '>=14.15.0'} - peerDependencies: - webpack: 5.x.x - webpack-cli: 5.x.x - dependencies: - webpack: 5.88.1(@swc/core@1.3.78)(webpack-cli@5.1.3) - webpack-cli: 5.1.3(webpack@5.88.1) - dev: true - - /@webpack-cli/serve@2.0.5(webpack-cli@5.1.3)(webpack@5.88.1): - resolution: {integrity: sha512-lqaoKnRYBdo1UgDX8uF24AfGMifWK19TxPmM5FHc2vAGxrJ/qtyUyFBWoY1tISZdelsQ5fBcOusifo5o5wSJxQ==} - engines: {node: '>=14.15.0'} - peerDependencies: - webpack: 5.x.x - webpack-cli: 5.x.x - webpack-dev-server: '*' - peerDependenciesMeta: - webpack-dev-server: - optional: true - dependencies: - webpack: 5.88.1(@swc/core@1.3.78)(webpack-cli@5.1.3) - webpack-cli: 5.1.3(webpack@5.88.1) - dev: true - /@xtuc/ieee754@1.2.0: resolution: {integrity: sha512-DX8nKgqcGwsc0eJSqYt5lwP4DH5FlHnmuWWBRy7X0NcaGR0ZtuyeESgMwTYVEtxmsNGY+qit4QYT/MIYTOTPeA==} dev: true @@ -6844,15 +6806,6 @@ packages: engines: {node: '>= 0.10'} dev: true - /clone-deep@4.0.1: - resolution: {integrity: sha512-neHB9xuzh/wk0dIHweyAXv2aPGZIVk3pLMe+/RNzINf17fe0OG96QroktYAUm7SM1PBnzTabaLboqqxDyMU+SQ==} - engines: {node: '>=6'} - dependencies: - is-plain-object: 2.0.4 - kind-of: 6.0.3 - shallow-clone: 3.0.1 - dev: true - /clone-response@1.0.3: resolution: {integrity: sha512-ROoL94jJH2dUVML2Y/5PEDNaSHgeOdSDicUyS7izcF63G6sTc/FTjLub4b8Il9S8S0beOfYt0TaA5qvFK+w0wA==} dependencies: @@ -8225,12 +8178,6 @@ packages: engines: {node: '>=6'} dev: false - /envinfo@7.10.0: - resolution: {integrity: sha512-ZtUjZO6l5mwTHvc1L9+1q5p/R3wTopcfqMW8r5t8SJSKqeVI/LtajORwRFEKpEFuekjD0VBjwu1HMxL4UalIRw==} - engines: {node: '>=4'} - hasBin: true - dev: true - /err-code@2.0.3: resolution: {integrity: sha512-2bmlRpNKBxT/CRmPOlyISQpNj+qSeYvcym/uT0Jx2bMOlKLtSy1ZmLuVxSEKKyor/N5yhvp/ZiG1oE3DEYMSFA==} dev: false @@ -9560,11 +9507,6 @@ packages: strnum: 1.0.5 dev: false - /fastest-levenshtein@1.0.16: - resolution: {integrity: sha512-eRnCtTTtGZFpQCwhJiUOuxPQWRXVKYDn0b2PeHfXL6/Zi53SLAzAHfVhVWK2AryC/WH05kGfxhFIPvTF0SXQzg==} - engines: {node: '>= 4.9.1'} - dev: true - /fastq@1.15.0: resolution: {integrity: sha512-wBrocU2LCXXa+lWBt8RoIRD89Fi8OdABODa/kEnyeyjS5aZO5/GNvI5sEINADqP/h8M29UHTHUb53sUu5Ihqdw==} dependencies: @@ -11018,11 +10960,6 @@ packages: engines: {node: '>= 0.10'} dev: true - /interpret@3.1.1: - resolution: {integrity: sha512-6xwYfHbajpoF0xLW+iwLkhwgvLoZDfjYfoFNu8ftMoXINzwuymNLd9u/KmwtdT2GbR+/Cz66otEGEVVUHX9QLQ==} - engines: {node: '>=10.13.0'} - dev: true - /invert-kv@1.0.0: resolution: {integrity: sha512-xgs2NH9AE66ucSq4cNG1nhSFghr5l6tdL15Pk+jl46bmmBapgoaY/AacXyaDznAqmGL99TiLSQgO/XazFSKYeQ==} engines: {node: '>=0.10.0'} @@ -16047,13 +15984,6 @@ packages: resolve: 1.22.4 dev: true - /rechoir@0.8.0: - resolution: {integrity: sha512-/vxpCXddiX8NGfGO/mTafwjq4aFa/71pvamip0++IQk3zG8cbCj0fifNPrjjF1XMXUne91jL9OoxmdykoEtifQ==} - engines: {node: '>= 10.13.0'} - dependencies: - resolve: 1.22.4 - dev: true - /reconnecting-websocket@4.4.0: resolution: {integrity: sha512-D2E33ceRPga0NvTDhJmphEgJ7FUYF0v4lr1ki0csq06OdlxKfugGzN0dSkxM/NfqCxYELK4KcaTOUOjTV6Dcng==} dev: false @@ -16656,13 +16586,6 @@ packages: crypt: 0.0.2 dev: true - /shallow-clone@3.0.1: - resolution: {integrity: sha512-/6KqX+GVUdqPuPPd2LxDDxzX6CAbjJehAAOKlNpqqUpAqPM6HeL8f+o3a+JsyGjn2lv0WY8UsTgUJjU9Ok55NA==} - engines: {node: '>=8'} - dependencies: - kind-of: 6.0.3 - dev: true - /sharp@0.32.5: resolution: {integrity: sha512-0dap3iysgDkNaPOaOL4X/0akdu0ma62GcdC2NBQ+93eqpePdDdr2/LM0sFdDSMmN7yS+odyZtPsb7tx/cYBKnQ==} engines: {node: '>=14.15.0'} @@ -17355,16 +17278,6 @@ packages: whet.extend: 0.9.9 dev: true - /swc-loader@0.2.3(@swc/core@1.3.78)(webpack@5.88.1): - resolution: {integrity: sha512-D1p6XXURfSPleZZA/Lipb3A8pZ17fP4NObZvFCDjK/OKljroqDpPmsBdTraWhVBqUNpcWBQY1imWdoPScRlQ7A==} - peerDependencies: - '@swc/core': ^1.2.147 - webpack: '>=2' - dependencies: - '@swc/core': 1.3.78 - webpack: 5.88.1(@swc/core@1.3.78)(webpack-cli@5.1.3) - dev: true - /swc-loader@0.2.3(@swc/core@1.3.78)(webpack@5.88.2): resolution: {integrity: sha512-D1p6XXURfSPleZZA/Lipb3A8pZ17fP4NObZvFCDjK/OKljroqDpPmsBdTraWhVBqUNpcWBQY1imWdoPScRlQ7A==} peerDependencies: @@ -17508,31 +17421,6 @@ packages: supports-hyperlinks: 2.3.0 dev: true - /terser-webpack-plugin@5.3.9(@swc/core@1.3.78)(webpack@5.88.1): - resolution: {integrity: sha512-ZuXsqE07EcggTWQjXUj+Aot/OMcD0bMKGgF63f7UxYcu5/AJF53aIpK1YoP5xR9l6s/Hy2b+t1AM0bLNPRuhwA==} - engines: {node: '>= 10.13.0'} - peerDependencies: - '@swc/core': '*' - esbuild: '*' - uglify-js: '*' - webpack: ^5.1.0 - peerDependenciesMeta: - '@swc/core': - optional: true - esbuild: - optional: true - uglify-js: - optional: true - dependencies: - '@jridgewell/trace-mapping': 0.3.19 - '@swc/core': 1.3.78 - jest-worker: 27.5.1 - schema-utils: 3.3.0 - serialize-javascript: 6.0.1 - terser: 5.19.2 - webpack: 5.88.1(@swc/core@1.3.78)(webpack-cli@5.1.3) - dev: true - /terser-webpack-plugin@5.3.9(@swc/core@1.3.78)(webpack@5.88.2): resolution: {integrity: sha512-ZuXsqE07EcggTWQjXUj+Aot/OMcD0bMKGgF63f7UxYcu5/AJF53aIpK1YoP5xR9l6s/Hy2b+t1AM0bLNPRuhwA==} engines: {node: '>= 10.13.0'} @@ -18845,93 +18733,11 @@ packages: engines: {node: '>=12'} dev: false - /webpack-cli@5.1.3(webpack@5.88.1): - resolution: {integrity: sha512-MTuk7NUMvEHQUSXCpvUrF1q2p0FJS40dPFfqQvG3jTWcgv/8plBNz2Kv2HXZiLGPnfmSAA5uCtCILO1JBmmkfw==} - engines: {node: '>=14.15.0'} - hasBin: true - peerDependencies: - '@webpack-cli/generators': '*' - webpack: 5.x.x - webpack-bundle-analyzer: '*' - webpack-dev-server: '*' - peerDependenciesMeta: - '@webpack-cli/generators': - optional: true - webpack-bundle-analyzer: - optional: true - webpack-dev-server: - optional: true - dependencies: - '@discoveryjs/json-ext': 0.5.7 - '@webpack-cli/configtest': 2.1.1(webpack-cli@5.1.3)(webpack@5.88.1) - '@webpack-cli/info': 2.0.2(webpack-cli@5.1.3)(webpack@5.88.1) - '@webpack-cli/serve': 2.0.5(webpack-cli@5.1.3)(webpack@5.88.1) - colorette: 2.0.20 - commander: 10.0.1 - cross-spawn: 7.0.3 - envinfo: 7.10.0 - fastest-levenshtein: 1.0.16 - import-local: 3.1.0 - interpret: 3.1.1 - rechoir: 0.8.0 - webpack: 5.88.1(@swc/core@1.3.78)(webpack-cli@5.1.3) - webpack-merge: 5.9.0 - dev: true - - /webpack-merge@5.9.0: - resolution: {integrity: sha512-6NbRQw4+Sy50vYNTw7EyOn41OZItPiXB8GNv3INSoe3PSFaHJEz3SHTrYVaRm2LilNGnFUzh0FAwqPEmU/CwDg==} - engines: {node: '>=10.0.0'} - dependencies: - clone-deep: 4.0.1 - wildcard: 2.0.1 - dev: true - /webpack-sources@3.2.3: resolution: {integrity: sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w==} engines: {node: '>=10.13.0'} dev: true - /webpack@5.88.1(@swc/core@1.3.78)(webpack-cli@5.1.3): - resolution: {integrity: sha512-FROX3TxQnC/ox4N+3xQoWZzvGXSuscxR32rbzjpXgEzWudJFEJBpdlkkob2ylrv5yzzufD1zph1OoFsLtm6stQ==} - engines: {node: '>=10.13.0'} - hasBin: true - peerDependencies: - webpack-cli: '*' - peerDependenciesMeta: - webpack-cli: - optional: true - dependencies: - '@types/eslint-scope': 3.7.4 - '@types/estree': 1.0.1 - '@webassemblyjs/ast': 1.11.6 - '@webassemblyjs/wasm-edit': 1.11.6 - '@webassemblyjs/wasm-parser': 1.11.6 - acorn: 8.10.0 - acorn-import-assertions: 1.9.0(acorn@8.10.0) - browserslist: 4.21.10 - chrome-trace-event: 1.0.3 - enhanced-resolve: 5.15.0 - es-module-lexer: 1.3.0 - eslint-scope: 5.1.1 - events: 3.3.0 - glob-to-regexp: 0.4.1 - graceful-fs: 4.2.11 - json-parse-even-better-errors: 2.3.1 - loader-runner: 4.3.0 - mime-types: 2.1.35 - neo-async: 2.6.2 - schema-utils: 3.3.0 - tapable: 2.2.1 - terser-webpack-plugin: 5.3.9(@swc/core@1.3.78)(webpack@5.88.1) - watchpack: 2.4.0 - webpack-cli: 5.1.3(webpack@5.88.1) - webpack-sources: 3.2.3 - transitivePeerDependencies: - - '@swc/core' - - esbuild - - uglify-js - dev: true - /webpack@5.88.2(@swc/core@1.3.78): resolution: {integrity: sha512-JmcgNZ1iKj+aiR0OvTYtWQqJwq37Pf683dY9bVORwVbUrDhLhdn/PlO2sHsFHPkj7sHNQF3JwaAkp49V+Sq1tQ==} engines: {node: '>=10.13.0'} @@ -19080,10 +18886,6 @@ packages: string-width: 4.2.3 dev: false - /wildcard@2.0.1: - resolution: {integrity: sha512-CC1bOL87PIWSBhDcTrdeLo6eGT7mCFtrg0uIJtqJUFyK+eJnzl8A1niH56uu7KMa5XFrtiV+AQuHO3n7DsHnLQ==} - dev: true - /with@7.0.2: resolution: {integrity: sha512-RNGKj82nUPg3g5ygxkQl0R937xLyho1J24ItRCBTr/m1YnZkzJy1hUiHUJrc/VlsDQzsCnInEGSg3bci0Lmd4w==} engines: {node: '>= 10.0.0'}