add webpack config to compile sw.js for browser

This commit is contained in:
Kaity A 2023-02-12 09:59:34 +00:00
parent 5a20d2af27
commit 93a72f31a5
3 changed files with 248 additions and 8 deletions

View file

@ -2,7 +2,7 @@
"name": "sw",
"private": true,
"scripts": {
"build": "pnpm swc src -d built -D",
"build": "webpack",
"watch": "pnpm swc src -d built -D -w",
"lint": "pnpm rome check \"src/**/*.ts\""
},
@ -16,6 +16,7 @@
"calckey-js": "^0.0.22",
"idb-keyval": "^6.2.0",
"swc-loader": "^0.2.3",
"webpack": "^5.75.0"
"webpack": "^5.75.0",
"webpack-cli": "^5.0.1"
}
}

View file

@ -0,0 +1,47 @@
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",
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('Calckey:'),
})
]
}

View file

@ -546,6 +546,7 @@ importers:
idb-keyval: ^6.2.0
swc-loader: ^0.2.3
webpack: ^5.75.0
webpack-cli: ^5.0.1
devDependencies:
'@swc/cli': 0.1.59_@swc+core@1.3.26
'@swc/core': 1.3.26
@ -553,7 +554,8 @@ importers:
calckey-js: 0.0.22
idb-keyval: 6.2.0
swc-loader: 0.2.3_v4imsvpumnwpgduroyqmpcfjiy
webpack: 5.75.0_@swc+core@1.3.26
webpack: 5.75.0_bix6ghzcb3jjkfxenpixt6qrpa
webpack-cli: 5.0.1_webpack@5.75.0
packages:
@ -923,6 +925,11 @@ 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'}
@ -2819,6 +2826,43 @@ packages:
resolution: {integrity: sha512-pUrWq3V5PiSGFLeLxoGqReTZmiiXwY3jRkIG5sLLKjyqNxrwm/04b4nw7LSmGWJcKk59XOM/YRTUwOzo4MMlow==}
dev: false
/@webpack-cli/configtest/2.0.1_rjsyjcrmk25kqsjzwkvj3a2evq:
resolution: {integrity: sha512-njsdJXJSiS2iNbQVS0eT8A/KPnmyH4pv1APj2K0d1wrZcBLw+yppxOy4CGqa0OxDJkzfL/XELDhD8rocnIwB5A==}
engines: {node: '>=14.15.0'}
peerDependencies:
webpack: 5.x.x
webpack-cli: 5.x.x
dependencies:
webpack: 5.75.0_bix6ghzcb3jjkfxenpixt6qrpa
webpack-cli: 5.0.1_webpack@5.75.0
dev: true
/@webpack-cli/info/2.0.1_rjsyjcrmk25kqsjzwkvj3a2evq:
resolution: {integrity: sha512-fE1UEWTwsAxRhrJNikE7v4EotYflkEhBL7EbajfkPlf6E37/2QshOy/D48Mw8G5XMFlQtS6YV42vtbG9zBpIQA==}
engines: {node: '>=14.15.0'}
peerDependencies:
webpack: 5.x.x
webpack-cli: 5.x.x
dependencies:
webpack: 5.75.0_bix6ghzcb3jjkfxenpixt6qrpa
webpack-cli: 5.0.1_webpack@5.75.0
dev: true
/@webpack-cli/serve/2.0.1_rjsyjcrmk25kqsjzwkvj3a2evq:
resolution: {integrity: sha512-0G7tNyS+yW8TdgHwZKlDWYXFA6OJQnoLCQvYKkQP0Q2X205PSQ6RNUj0M+1OB/9gRQaUZ/ccYfaxd0nhaWKfjw==}
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.75.0_bix6ghzcb3jjkfxenpixt6qrpa
webpack-cli: 5.0.1_webpack@5.75.0
dev: true
/@xtuc/ieee754/1.2.0:
resolution: {integrity: sha512-DX8nKgqcGwsc0eJSqYt5lwP4DH5FlHnmuWWBRy7X0NcaGR0ZtuyeESgMwTYVEtxmsNGY+qit4QYT/MIYTOTPeA==}
dev: true
@ -4145,6 +4189,15 @@ 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.2:
resolution: {integrity: sha512-yjLXh88P599UOyPTFX0POsd7WxnbsVsGohcwzHOLspIhhpalPw1BcqED8NblyZLKcGrL8dTgMlcaZxV2jAD41Q==}
dependencies:
@ -5570,6 +5623,12 @@ packages:
engines: {node: '>=6'}
dev: false
/envinfo/7.8.1:
resolution: {integrity: sha512-/o+BXHmB7ocbHEAs6F2EnG0ogybVVUdkRunTT2glZU9XAaGmhqskrvKwqXuDfNjEO0LZKWdejEEpnq8aM0tOaw==}
engines: {node: '>=4'}
hasBin: true
dev: true
/err-code/2.0.3:
resolution: {integrity: sha512-2bmlRpNKBxT/CRmPOlyISQpNj+qSeYvcym/uT0Jx2bMOlKLtSy1ZmLuVxSEKKyor/N5yhvp/ZiG1oE3DEYMSFA==}
dev: false
@ -6083,6 +6142,11 @@ 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:
@ -6210,7 +6274,6 @@ packages:
dependencies:
locate-path: 5.0.0
path-exists: 4.0.0
dev: false
/find-up/5.0.0:
resolution: {integrity: sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==}
@ -7278,6 +7341,15 @@ packages:
engines: {node: '>=6'}
dev: true
/import-local/3.1.0:
resolution: {integrity: sha512-ASB07uLtnDs1o6EHjKpX34BKYDSqnFerfTOJL2HvMqF70LnxpjkzDB8J44oT9pu4AMPkQwf8jl6szgvNd2tRIg==}
engines: {node: '>=8'}
hasBin: true
dependencies:
pkg-dir: 4.2.0
resolve-cwd: 3.0.0
dev: true
/imurmurhash/0.1.4:
resolution: {integrity: sha512-JmXMZ6wuvDmLiHEml9ykzqO6lwFbof0GG4IkcGaENdCRDDmMVnny7s5HsIgHCbaq0w2MyPhDqkhTUgS2LU2PHA==}
engines: {node: '>=0.8.19'}
@ -7340,6 +7412,11 @@ 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
/into-stream/3.1.0:
resolution: {integrity: sha512-TcdjPibTksa1NQximqep2r17ISRiNE9fwlfbg3F8ANdvP5/yrFTew86VcO//jk4QTaMlbjypPBq76HN2zaKfZQ==}
engines: {node: '>=4'}
@ -8542,7 +8619,6 @@ packages:
engines: {node: '>=8'}
dependencies:
p-locate: 4.1.0
dev: false
/locate-path/6.0.0:
resolution: {integrity: sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==}
@ -9676,7 +9752,6 @@ packages:
engines: {node: '>=6'}
dependencies:
p-try: 2.2.0
dev: false
/p-limit/3.1.0:
resolution: {integrity: sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==}
@ -9689,7 +9764,6 @@ packages:
engines: {node: '>=8'}
dependencies:
p-limit: 2.3.0
dev: false
/p-locate/5.0.0:
resolution: {integrity: sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==}
@ -9727,7 +9801,6 @@ packages:
/p-try/2.2.0:
resolution: {integrity: sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==}
engines: {node: '>=6'}
dev: false
/packet-reader/1.0.0:
resolution: {integrity: sha512-HAKu/fG3HpHFO0AA8WE8q2g+gBJaZ9MG7fcKk+IJPLTGAD6Psw4443l+9DGRbOIh3/aXr7Phy0TjilYivJo5XQ==}
@ -9996,6 +10069,13 @@ packages:
engines: {node: '>=0.10.0'}
dev: true
/pkg-dir/4.2.0:
resolution: {integrity: sha512-HRDzbaKjC+AOWVXxAU/x54COGeIv9eb+6CkDSQoNTt4XyWoIJvuPsXizxu/Fr23EiekbtZwmh1IcIG/l/a10GQ==}
engines: {node: '>=8'}
dependencies:
find-up: 4.1.0
dev: true
/plimit-lit/1.5.0:
resolution: {integrity: sha512-Eb/MqCb1Iv/ok4m1FqIXqvUKPISufcjZ605hl3KM/n8GaX8zfhtgdLwZU3vKjuHGh2O9Rjog/bHTq8ofIShdng==}
dependencies:
@ -10767,6 +10847,13 @@ packages:
resolve: 1.22.1
dev: true
/rechoir/0.8.0:
resolution: {integrity: sha512-/vxpCXddiX8NGfGO/mTafwjq4aFa/71pvamip0++IQk3zG8cbCj0fifNPrjjF1XMXUne91jL9OoxmdykoEtifQ==}
engines: {node: '>= 10.13.0'}
dependencies:
resolve: 1.22.1
dev: true
/reconnecting-websocket/4.4.0:
resolution: {integrity: sha512-D2E33ceRPga0NvTDhJmphEgJ7FUYF0v4lr1ki0csq06OdlxKfugGzN0dSkxM/NfqCxYELK4KcaTOUOjTV6Dcng==}
@ -10959,6 +11046,13 @@ packages:
resolution: {integrity: sha512-0a1F4l73/ZFZOakJnQ3FvkJ2+gSTQWz/r2KE5OdDY0TxPm5h4GkqkWWfM47T7HsbnOtcJVEF4epCVy6u7Q3K+g==}
dev: false
/resolve-cwd/3.0.0:
resolution: {integrity: sha512-OrZaX2Mb+rJCpH/6CpSqt9xFVpN++x01XnN2ie9g6P5/3xelLAkXWVADpdz1IHD/KFfEXyE6V0U01OQ3UO2rEg==}
engines: {node: '>=8'}
dependencies:
resolve-from: 5.0.0
dev: true
/resolve-dir/1.0.1:
resolution: {integrity: sha512-R7uiTjECzvOsWSfdM0QKFNBVFcK27aHOUwdvK53BcW8zqnGdYp0Fbj82cy54+2A4P2tFM22J5kRfe1R+lM/1yg==}
engines: {node: '>=0.10.0'}
@ -10971,6 +11065,11 @@ packages:
resolution: {integrity: sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==}
engines: {node: '>=4'}
/resolve-from/5.0.0:
resolution: {integrity: sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw==}
engines: {node: '>=8'}
dev: true
/resolve-options/1.1.0:
resolution: {integrity: sha512-NYDgziiroVeDC29xq7bp/CacZERYsA9bXYd1ZmcJlF3BcrZv5pTb4NG7SjdyKDnXZ84aC4vo2u6sNKIA1LCu/A==}
engines: {node: '>= 0.10'}
@ -11273,6 +11372,13 @@ 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.31.3:
resolution: {integrity: sha512-XcR4+FCLBFKw1bdB+GEhnUNXNXvnt0tDo4WsBsraKymuo/IAuPuCBVAL2wIkUw2r/dwFW5Q5+g66Kwl2dgDFVg==}
engines: {node: '>=14.15.0'}
@ -12906,6 +13012,47 @@ packages:
engines: {node: '>=12'}
dev: false
/webpack-cli/5.0.1_webpack@5.75.0:
resolution: {integrity: sha512-S3KVAyfwUqr0Mo/ur3NzIp6jnerNpo7GUO6so51mxLi1spqsA17YcMXy0WOIJtBSnj748lthxC6XLbNKh/ZC+A==}
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.0.1_rjsyjcrmk25kqsjzwkvj3a2evq
'@webpack-cli/info': 2.0.1_rjsyjcrmk25kqsjzwkvj3a2evq
'@webpack-cli/serve': 2.0.1_rjsyjcrmk25kqsjzwkvj3a2evq
colorette: 2.0.19
commander: 9.5.0
cross-spawn: 7.0.3
envinfo: 7.8.1
fastest-levenshtein: 1.0.16
import-local: 3.1.0
interpret: 3.1.1
rechoir: 0.8.0
webpack: 5.75.0_bix6ghzcb3jjkfxenpixt6qrpa
webpack-merge: 5.8.0
dev: true
/webpack-merge/5.8.0:
resolution: {integrity: sha512-/SaI7xY0831XwP6kzuwhKWVKDP9t1QY1h65lAFLbZqMPIuYcD9QAW4u9STIbU9kaJbPBB/geU/gLr1wDjOhQ+Q==}
engines: {node: '>=10.0.0'}
dependencies:
clone-deep: 4.0.1
wildcard: 2.0.0
dev: true
/webpack-sources/3.2.3:
resolution: {integrity: sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w==}
engines: {node: '>=10.13.0'}
@ -12951,6 +13098,47 @@ packages:
- uglify-js
dev: true
/webpack/5.75.0_bix6ghzcb3jjkfxenpixt6qrpa:
resolution: {integrity: sha512-piaIaoVJlqMsPtX/+3KTTO6jfvrSYgauFVdt8cr9LTHKmcq/AMd4mhzsiP7ZF/PGRNPGA8336jldh9l2Kt2ogQ==}
engines: {node: '>=10.13.0'}
hasBin: true
peerDependencies:
webpack-cli: '*'
peerDependenciesMeta:
webpack-cli:
optional: true
dependencies:
'@types/eslint-scope': 3.7.4
'@types/estree': 0.0.51
'@webassemblyjs/ast': 1.11.1
'@webassemblyjs/wasm-edit': 1.11.1
'@webassemblyjs/wasm-parser': 1.11.1
acorn: 8.8.1
acorn-import-assertions: 1.8.0_acorn@8.8.1
browserslist: 4.21.4
chrome-trace-event: 1.0.3
enhanced-resolve: 5.12.0
es-module-lexer: 0.9.3
eslint-scope: 5.1.1
events: 3.3.0
glob-to-regexp: 0.4.1
graceful-fs: 4.2.10
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.1.1
tapable: 2.2.1
terser-webpack-plugin: 5.3.6_v4imsvpumnwpgduroyqmpcfjiy
watchpack: 2.4.0
webpack-cli: 5.0.1_webpack@5.75.0
webpack-sources: 3.2.3
transitivePeerDependencies:
- '@swc/core'
- esbuild
- uglify-js
dev: true
/websocket/1.0.34:
resolution: {integrity: sha512-PRDso2sGwF6kM75QykIesBijKSVceR6jL2G8NGYyq2XrItNC2P5/qL5XeR056GhA+Ly7JMFvJb9I312mJfmqnQ==}
engines: {node: '>=4.0.0'}
@ -13036,6 +13224,10 @@ packages:
string-width: 4.2.3
dev: false
/wildcard/2.0.0:
resolution: {integrity: sha512-JcKqAHLPxcdb9KM49dufGXn2x3ssnfjbcaQdLlfZsL9rH9wgDQjUtDxbo8NE0F6SFvydeu1VhZe7hZuHsB2/pw==}
dev: true
/with/7.0.2:
resolution: {integrity: sha512-RNGKj82nUPg3g5ygxkQl0R937xLyho1J24ItRCBTr/m1YnZkzJy1hUiHUJrc/VlsDQzsCnInEGSg3bci0Lmd4w==}
engines: {node: '>= 10.0.0'}