From ae1c738f70c2920a910701190886b4f75f6b5d75 Mon Sep 17 00:00:00 2001 From: xream Date: Sat, 3 Feb 2024 21:30:27 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E5=BC=80=E5=8F=91=E6=B5=81=E7=A8=8B?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=20esbuild?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 12 +++++++++++- backend/dev-esbuild.js | 24 ++++++++++++++++++++++++ backend/package.json | 2 ++ backend/src/core/proxy-utils/index.js | 4 ++-- 4 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 backend/dev-esbuild.js diff --git a/README.md b/README.md index 3d9e73e..a0e99b1 100644 --- a/README.md +++ b/README.md @@ -84,15 +84,25 @@ Install `pnpm` Go to `backend` directories, install node dependencies: ``` -pnpm install +pnpm i ``` 1. In `backend`, run the backend server on http://localhost:3000 +babel(old school) + ``` pnpm start ``` +or + +esbuild(experimental) + +``` +pnpm run --parallel "/^dev:.*/" +``` + ## LICENSE This project is under the GPL V3 LICENSE. diff --git a/backend/dev-esbuild.js b/backend/dev-esbuild.js new file mode 100644 index 0000000..dd44c57 --- /dev/null +++ b/backend/dev-esbuild.js @@ -0,0 +1,24 @@ +#!/usr/bin/env node +const { build } = require('esbuild'); + +!(async () => { + const artifacts = [{ src: 'src/main.js', dest: 'sub-store.min.js' }]; + + for await (const artifact of artifacts) { + await build({ + entryPoints: [artifact.src], + bundle: true, + minify: false, + sourcemap: false, + platform: 'node', + format: 'cjs', + outfile: artifact.dest, + }); + } +})() + .catch((e) => { + console.log(e); + }) + .finally(() => { + console.log('done'); + }); diff --git a/backend/package.json b/backend/package.json index 71e7100..0d0e425 100644 --- a/backend/package.json +++ b/backend/package.json @@ -8,6 +8,8 @@ "test": "gulp peggy && npx cross-env BABEL_ENV=test mocha src/test/**/*.spec.js --require @babel/register --recursive", "serve": "node sub-store.min.js", "start": "nodemon -w src -w package.json --exec babel-node src/main.js", + "dev:esbuild": "nodemon -w src -w package.json dev-esbuild.js", + "dev:run": "nodemon -w sub-store.json -w sub-store.min.js sub-store.min.js", "build": "gulp", "bundle": "node bundle.js" }, diff --git a/backend/src/core/proxy-utils/index.js b/backend/src/core/proxy-utils/index.js index 4b535c4..89cc328 100644 --- a/backend/src/core/proxy-utils/index.js +++ b/backend/src/core/proxy-utils/index.js @@ -63,7 +63,7 @@ function parse(raw) { return proxies; } -async function process(proxies, operators = [], targetPlatform, source) { +async function processFn(proxies, operators = [], targetPlatform, source) { for (const item of operators) { // process script let script; @@ -188,7 +188,7 @@ function produce(proxies, targetPlatform, type, opts = {}) { export const ProxyUtils = { parse, - process, + process: processFn, produce, isIPv4, isIPv6,