From 1b7f0df635c20dbe3d7d12ee74ae073038035fab Mon Sep 17 00:00:00 2001 From: j2rong4cn <253551464@qq.com> Date: Fri, 25 Aug 2023 14:43:33 +0800 Subject: [PATCH 1/3] =?UTF-8?q?node-proxy/webpack.config.js=E5=8E=BB?= =?UTF-8?q?=E6=8E=89webpack-node-externals?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- node-proxy/webpack.config.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/node-proxy/webpack.config.js b/node-proxy/webpack.config.js index 5b1afab..8a7f34f 100644 --- a/node-proxy/webpack.config.js +++ b/node-proxy/webpack.config.js @@ -1,6 +1,6 @@ const CopyPlugin = require('copy-webpack-plugin') const path = require('path') -const nodeExternals = require('webpack-node-externals') +// const nodeExternals = require('webpack-node-externals') const TerserPlugin = require('terser-webpack-plugin') const output = { @@ -44,7 +44,7 @@ module.exports = { }), ], target: 'node', - externals: [nodeExternals()], + // externals: [nodeExternals()], mode: 'production', optimization: { minimize: true, From caf24f7df0d9cc21b4222873d77d7734ac2cccdc Mon Sep 17 00:00:00 2001 From: j2rong4cn <253551464@qq.com> Date: Fri, 25 Aug 2023 14:45:18 +0800 Subject: [PATCH 2/3] =?UTF-8?q?node-proxy/webpack.config.js=20=E5=8F=96?= =?UTF-8?q?=E6=B6=88=E6=A0=BC=E5=BC=8F=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- node-proxy/webpack.config.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/node-proxy/webpack.config.js b/node-proxy/webpack.config.js index 8a7f34f..c5f480c 100644 --- a/node-proxy/webpack.config.js +++ b/node-proxy/webpack.config.js @@ -63,12 +63,12 @@ module.exports = { keep_fnames: true, // 是否保留类名 keep_classnames: true, - format: { - // 输出格式化 - beautify: true, - // 保留注释 - comments: true, - }, + // format: { + // // 输出格式化 + // beautify: true, + // // 保留注释 + // comments: true, + // }, }, }), ], From 23773b668cc5dfdb74da98f437a7bcd9b641e135 Mon Sep 17 00:00:00 2001 From: j2rong4cn <253551464@qq.com> Date: Fri, 25 Aug 2023 17:43:40 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=BC=96=E8=AF=91?= =?UTF-8?q?=EF=BC=8C=E4=BD=93=E7=A7=AF=E5=87=8F=E5=B0=9120~30%?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- node-proxy/package-lock.json | 69 ++++++++++--------------- node-proxy/package.json | 18 +------ node-proxy/pkgconfig.dist.json | 12 +++++ node-proxy/webpack.config.js | 76 --------------------------- node-proxy/webpack.config.ts | 93 ++++++++++++++++++++++++++++++++++ 5 files changed, 135 insertions(+), 133 deletions(-) create mode 100644 node-proxy/pkgconfig.dist.json delete mode 100644 node-proxy/webpack.config.js create mode 100644 node-proxy/webpack.config.ts diff --git a/node-proxy/package-lock.json b/node-proxy/package-lock.json index d981daa..104d790 100644 --- a/node-proxy/package-lock.json +++ b/node-proxy/package-lock.json @@ -22,9 +22,6 @@ "tsconfig-paths": "^4.2.0", "typescript": "^5.1.6" }, - "bin": { - "alist-encrypt": "dist/index.js" - }, "devDependencies": { "@typescript-eslint/eslint-plugin": "^5.55.0", "@typescript-eslint/parser": "^5.55.0", @@ -38,8 +35,7 @@ "ts-loader": "^9.4.4", "ts-node-dev": "^2.0.0", "webpack": "^5.88.2", - "webpack-cli": "^5.1.4", - "webpack-node-externals": "^3.0.0" + "webpack-cli": "^5.1.4" } }, "node_modules/@aashutoshrathi/word-wrap": { @@ -154,9 +150,9 @@ } }, "node_modules/@eslint-community/regexpp": { - "version": "4.6.2", - "resolved": "https://registry.npmmirror.com/@eslint-community/regexpp/-/regexpp-4.6.2.tgz", - "integrity": "sha512-pPTNuaAG3QMH+buKyBIGJs3g/S5y0caxw0ygM3YyE6yJFySwiGGSzA+mM3KJ8QQvzeLh3blwgSonkFjgQdxzMw==", + "version": "4.8.0", + "resolved": "https://registry.npmmirror.com/@eslint-community/regexpp/-/regexpp-4.8.0.tgz", + "integrity": "sha512-JylOEEzDiOryeUnFbQz+oViCXS0KsvR1mvHkoMiu5+UiBvy+RYX7tzlIIIEstF/gVa2tj9AQXk3dgnxv6KxhFg==", "dev": true, "engines": { "node": "^12.0.0 || ^14.0.0 || >=16.0.0" @@ -396,9 +392,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "20.5.0", - "resolved": "https://registry.npmmirror.com/@types/node/-/node-20.5.0.tgz", - "integrity": "sha512-Mgq7eCtoTjT89FqNoTzzXg2XvCi5VMhRV6+I2aYanc6kQCBImeNaAYRs/DyoVqk1YEUJK5gN9VO7HRIdz4Wo3Q==" + "version": "20.5.6", + "resolved": "https://registry.npmmirror.com/@types/node/-/node-20.5.6.tgz", + "integrity": "sha512-Gi5wRGPbbyOTX+4Y2iULQ27oUPrefaB0PxGQJnfyWN3kvEDGM3mIB5M/gQLmitZf7A9FmLeaqxD3L1CXpm3VKQ==" }, "node_modules/@types/semver": { "version": "7.5.0", @@ -1138,9 +1134,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001521", - "resolved": "https://registry.npmmirror.com/caniuse-lite/-/caniuse-lite-1.0.30001521.tgz", - "integrity": "sha512-fnx1grfpEOvDGH+V17eccmNjucGUnCbP6KL+l5KqBIerp26WK/+RQ7CIDE37KGJjaPyqWXXlFUyKiWmvdNNKmQ==", + "version": "1.0.30001523", + "resolved": "https://registry.npmmirror.com/caniuse-lite/-/caniuse-lite-1.0.30001523.tgz", + "integrity": "sha512-I5q5cisATTPZ1mc588Z//pj/Ox80ERYDfR71YnvY7raS/NOk8xXlZcB0sF7JdqaV//kOaa6aus7lRfpdnt1eBA==", "dev": true }, "node_modules/chalk": { @@ -1570,9 +1566,9 @@ "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==" }, "node_modules/electron-to-chromium": { - "version": "1.4.495", - "resolved": "https://registry.npmmirror.com/electron-to-chromium/-/electron-to-chromium-1.4.495.tgz", - "integrity": "sha512-mwknuemBZnoOCths4GtpU/SDuVMp3uQHKa2UNJT9/aVD6WVRjGpXOxRGX7lm6ILIenTdGXPSTCTDaWos5tEU8Q==", + "version": "1.4.502", + "resolved": "https://registry.npmmirror.com/electron-to-chromium/-/electron-to-chromium-1.4.502.tgz", + "integrity": "sha512-xqeGw3Gr6o3uyHy/yKjdnDQHY2RQvXcGC2cfHjccK1IGkH6cX1WQBN8EeC/YpwPhGkBaikDTecJ8+ssxSVRQlw==", "dev": true }, "node_modules/emoji-regex": { @@ -2087,9 +2083,9 @@ "dev": true }, "node_modules/fsevents": { - "version": "2.3.2", - "resolved": "https://registry.npmmirror.com/fsevents/-/fsevents-2.3.2.tgz", - "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", + "version": "2.3.3", + "resolved": "https://registry.npmmirror.com/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", "dev": true, "hasInstallScript": true, "optional": true, @@ -3168,9 +3164,9 @@ "dev": true }, "node_modules/node-abi": { - "version": "3.46.0", - "resolved": "https://registry.npmmirror.com/node-abi/-/node-abi-3.46.0.tgz", - "integrity": "sha512-LXvP3AqTIrtvH/jllXjkNVbYifpRbt9ThTtymSMSuHmhugQLAWr99QQFTm+ZRht9ziUvdGOgB+esme1C6iE6Lg==", + "version": "3.47.0", + "resolved": "https://registry.npmmirror.com/node-abi/-/node-abi-3.47.0.tgz", + "integrity": "sha512-2s6B2CWZM//kPgwnuI0KrYwNjfdByE25zvAaEpq9IH4zcNsarH8Ihu/UuX6XMPEogDAxkuUFeZn60pXNHAqn3A==", "dev": true, "dependencies": { "semver": "^7.3.5" @@ -3180,9 +3176,9 @@ } }, "node_modules/node-fetch": { - "version": "2.6.12", - "resolved": "https://registry.npmmirror.com/node-fetch/-/node-fetch-2.6.12.tgz", - "integrity": "sha512-C/fGU2E8ToujUivIO0H+tpQ6HWo4eEmchoPIoXtxCrVghxdKq+QOHqEZW7tuP3KlV3bC8FRMO5nMCC7Zm1VP6g==", + "version": "2.7.0", + "resolved": "https://registry.npmmirror.com/node-fetch/-/node-fetch-2.7.0.tgz", + "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", "dev": true, "dependencies": { "whatwg-url": "^5.0.0" @@ -4682,9 +4678,9 @@ } }, "node_modules/tslib": { - "version": "2.6.1", - "resolved": "https://registry.npmmirror.com/tslib/-/tslib-2.6.1.tgz", - "integrity": "sha512-t0hLfiEKfMUoqhG+U1oid7Pva4bbDPHYfJNiB7BiIjRkj1pyC++4N3huJfqY6aRH6VTB0rvtzQwjM4K6qpfOig==", + "version": "2.6.2", + "resolved": "https://registry.npmmirror.com/tslib/-/tslib-2.6.2.tgz", + "integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==", "dev": true }, "node_modules/tsscmp": { @@ -4762,9 +4758,9 @@ } }, "node_modules/typescript": { - "version": "5.1.6", - "resolved": "https://registry.npmmirror.com/typescript/-/typescript-5.1.6.tgz", - "integrity": "sha512-zaWCozRZ6DLEWAWFrVDz1H6FVXzUSfTy5FUMWsQlU8Ym5JP9eO4xkTIROFCQvhQf61z6O/G6ugw3SgAnvvm+HA==", + "version": "5.2.2", + "resolved": "https://registry.npmmirror.com/typescript/-/typescript-5.2.2.tgz", + "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==", "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -4980,15 +4976,6 @@ "node": ">=10.0.0" } }, - "node_modules/webpack-node-externals": { - "version": "3.0.0", - "resolved": "https://registry.npmmirror.com/webpack-node-externals/-/webpack-node-externals-3.0.0.tgz", - "integrity": "sha512-LnL6Z3GGDPht/AigwRh2dvL9PQPFQ8skEpVrWZXLWBYmqcaojHNN0onvHzie6rq7EWKrrBfPYqNEzTJgiwEQDQ==", - "dev": true, - "engines": { - "node": ">=6" - } - }, "node_modules/webpack-sources": { "version": "3.2.3", "resolved": "https://registry.npmmirror.com/webpack-sources/-/webpack-sources-3.2.3.tgz", diff --git a/node-proxy/package.json b/node-proxy/package.json index 8739316..0fa8065 100644 --- a/node-proxy/package.json +++ b/node-proxy/package.json @@ -8,7 +8,7 @@ "serve": "ts-node -r tsconfig-paths/register app.js", "test": "echo \"Error: no test specified\" && exit 1", "webpack": "npx webpack", - "build": "npm run webpack && pkg --compress GZip . ", + "build": "npm run webpack && pkg --compress GZip dist", "docker": "npm run webpack && sudo docker build -t prophet310/alist-encrypt:beta . ", "docker-arm": "npm run webpack && sudo docker build -t prophet310/alist-encrypt:beta-arm . ", "docker-all": "npm run webpack && sudo docker buildx build -t prophet310/alist-encrypt:beta-1.0 --platform=linux/arm64,linux/amd64 . --push " @@ -43,20 +43,6 @@ "ts-loader": "^9.4.4", "ts-node-dev": "^2.0.0", "webpack": "^5.88.2", - "webpack-cli": "^5.1.4", - "webpack-node-externals": "^3.0.0" - }, - "bin": "dist/index.js", - "pkg": { - "options": [ - "experimental-modules" - ], - "scripts": [ - "dist/PRGAThreadCom.js" - ], - "assets": [ - "dist/public/**/*" - ], - "outputPath": "build" + "webpack-cli": "^5.1.4" } } diff --git a/node-proxy/pkgconfig.dist.json b/node-proxy/pkgconfig.dist.json new file mode 100644 index 0000000..09966fa --- /dev/null +++ b/node-proxy/pkgconfig.dist.json @@ -0,0 +1,12 @@ +{ + "bin": "index.js", + "pkg": { + "scripts": [ + "PRGAThreadCom.js" + ], + "assets": [ + "public/**/*" + ], + "outputPath": "build" + } +} diff --git a/node-proxy/webpack.config.js b/node-proxy/webpack.config.js deleted file mode 100644 index c5f480c..0000000 --- a/node-proxy/webpack.config.js +++ /dev/null @@ -1,76 +0,0 @@ -const CopyPlugin = require('copy-webpack-plugin') -const path = require('path') -// const nodeExternals = require('webpack-node-externals') -const TerserPlugin = require('terser-webpack-plugin') - -const output = { - filename: '[name].js', - path: path.resolve('./dist'), -} - -module.exports = { - entry: { index: path.resolve('./app.js'), PRGAThreadCom: path.resolve('./src/utils/PRGAThreadCom.js') }, - output, - module: { - rules: [ - { - test: /\.[tj]s$/i, - use: [ - { - loader: 'ts-loader', - options: { - transpileOnly: true, // 只做语言转换,而不做类型检查 - }, - }, - ], - exclude: /node_modules/, - }, - ], - }, - resolve: { - extensions: ['.ts', '.js'], - alias: { - '@': path.resolve('./src'), - }, - }, - plugins: [ - new CopyPlugin({ - patterns: [ - { - from: path.resolve('./public'), - to: path.resolve(output.path, 'public'), - }, - ], - }), - ], - target: 'node', - // externals: [nodeExternals()], - mode: 'production', - optimization: { - minimize: true, - minimizer: [ - new TerserPlugin({ - // 是否启用多线程 - parallel: true, - // 是否将注释剥离到单独的文件中 - extractComments: false, - terserOptions: { - // 是否压缩代码 - compress: true, - // 是否压缩标识符 - mangle: true, - // 是否保留函数名 - keep_fnames: true, - // 是否保留类名 - keep_classnames: true, - // format: { - // // 输出格式化 - // beautify: true, - // // 保留注释 - // comments: true, - // }, - }, - }), - ], - }, -} diff --git a/node-proxy/webpack.config.ts b/node-proxy/webpack.config.ts new file mode 100644 index 0000000..9cb0b5f --- /dev/null +++ b/node-proxy/webpack.config.ts @@ -0,0 +1,93 @@ +import fs from 'fs' +import CopyPlugin from 'copy-webpack-plugin' +import path from 'path' +import TerserPlugin from 'terser-webpack-plugin' +import webpack from 'webpack' + +const output = { + filename: '[name].js', + path: path.resolve('./dist'), +} +export default () => { + return { + entry: { index: path.resolve('./app.js'), PRGAThreadCom: path.resolve('./src/utils/PRGAThreadCom.js') }, + output, + module: { + rules: [ + { + test: /\.[tj]s$/i, + use: [ + { + loader: 'ts-loader', + options: { + transpileOnly: true, // 只做语言转换,而不做类型检查 + }, + }, + ], + exclude: /node_modules/, + }, + ], + }, + resolve: { + extensions: ['.ts', '.js'], + alias: { + '@': path.resolve('./src'), + }, + }, + plugins: [ + new CopyPlugin({ + patterns: [ + { + from: path.resolve('./public'), + to: path.join(output.path, 'public'), + }, + ], + }), + new PkgConfig(), + ], + target: 'node', + // externals: [nodeExternals()], + mode: 'production', + optimization: { + minimize: true, + minimizer: [ + new TerserPlugin({ + // 是否启用多线程 + parallel: true, + // 是否将注释剥离到单独的文件中 + extractComments: false, + terserOptions: { + // 是否压缩代码 + compress: true, + // 是否压缩标识符 + mangle: true, + // 是否保留函数名 + keep_fnames: true, + // 是否保留类名 + keep_classnames: true, + // format: { + // // 输出格式化 + // beautify: true, + // // 保留注释 + // comments: true, + // }, + }, + }), + ], + }, + } +} + +class PkgConfig { + apply(compiler: webpack.Compiler) { + compiler.hooks.afterEmit.tap('DistConfig', () => { + const conf = JSON.parse(fs.readFileSync(path.resolve('./package.json'), 'utf-8')) + const pkg_conf = JSON.parse(fs.readFileSync(path.resolve('./pkgconfig.dist.json'), 'utf-8')) + pkg_conf['name'] = conf['name'] + pkg_conf['version'] = conf['version'] + const dist_conf_path = path.join(output.path, 'package.json') + fs.writeFileSync(dist_conf_path, JSON.stringify(pkg_conf), { encoding: 'utf-8' }) + console.log(dist_conf_path, pkg_conf) + }) + } +}