commit 93f905edd92195a42100b13823be9c9828008976 Author: npmrun <1549469775@qq.com> Date: Tue May 12 23:01:02 2026 +0800 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9b1ee42 --- /dev/null +++ b/.gitignore @@ -0,0 +1,175 @@ +# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore + +# Logs + +logs +_.log +npm-debug.log_ +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# Caches + +.cache + +# Diagnostic reports (https://nodejs.org/api/report.html) + +report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json + +# Runtime data + +pids +_.pid +_.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover + +lib-cov + +# Coverage directory used by tools like istanbul + +coverage +*.lcov + +# nyc test coverage + +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) + +.grunt + +# Bower dependency directory (https://bower.io/) + +bower_components + +# node-waf configuration + +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) + +build/Release + +# Dependency directories + +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) + +web_modules/ + +# TypeScript cache + +*.tsbuildinfo + +# Optional npm cache directory + +.npm + +# Optional eslint cache + +.eslintcache + +# Optional stylelint cache + +.stylelintcache + +# Microbundle cache + +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history + +.node_repl_history + +# Output of 'npm pack' + +*.tgz + +# Yarn Integrity file + +.yarn-integrity + +# dotenv environment variable files + +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# parcel-bundler cache (https://parceljs.org/) + +.parcel-cache + +# Next.js build output + +.next +out + +# Nuxt.js build / generate output + +.nuxt +dist + +# Gatsby files + +# Comment in the public line in if your project uses Gatsby and not Next.js + +# https://nextjs.org/blog/next-9-1#public-directory-support + +# public + +# vuepress build output + +.vuepress/dist + +# vuepress v2.x temp and cache directory + +.temp + +# Docusaurus cache and generated files + +.docusaurus + +# Serverless directories + +.serverless/ + +# FuseBox cache + +.fusebox/ + +# DynamoDB Local files + +.dynamodb/ + +# TernJS port file + +.tern-port + +# Stores VSCode versions used for testing VSCode extensions + +.vscode-test + +# yarn v2 + +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* + +# IntelliJ based IDEs +.idea + +# Finder (MacOS) folder config +.DS_Store diff --git a/README.md b/README.md new file mode 100644 index 0000000..7bfe731 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +bun build ./main.js --compile --minify --windows-hide-console --outfile myapp +bun build ./main.js --compile --minify --windows-hide-console --windows-icon=assets/icon.ico --outfile myapp + +bun build --compile --minify --sourcemap --target=bun-windows-x64 --windows-hide-console ./main.ts --outfile myapp --windows-icon=./assets/icon.ico + +bun build --compile --minify --sourcemap --target=bun-windows-x64 --windows-hide-console --windows-icon=output.ico ./main.ts --outfile myapp + +bun build ./main.js --compile --minify --windows-icon ./assets/icon.ico --windows-hide-console --outfile myapp + +https://github.com/tr1ckydev/webview-bun +https://www.xgs.cc/note/other/bun-windows-gui + +.\hidecmd.bat todoapp.exe + +安装了https://imagemagick.org/script/convert.php 这个工具 \ No newline at end of file diff --git a/aaa.txt b/aaa.txt new file mode 100644 index 0000000..19cd8a1 --- /dev/null +++ b/aaa.txt @@ -0,0 +1 @@ +D:\@code\@demo\webview-bun-demo\main copy.ts \ No newline at end of file diff --git a/assets/icon.ico b/assets/icon.ico new file mode 100644 index 0000000..e144137 Binary files /dev/null and b/assets/icon.ico differ diff --git a/assets/icons/icon_128x128.ico b/assets/icons/icon_128x128.ico new file mode 100644 index 0000000..d6ed889 Binary files /dev/null and b/assets/icons/icon_128x128.ico differ diff --git a/assets/icons/icon_16x16.ico b/assets/icons/icon_16x16.ico new file mode 100644 index 0000000..80752ed Binary files /dev/null and b/assets/icons/icon_16x16.ico differ diff --git a/assets/icons/icon_256x256.ico b/assets/icons/icon_256x256.ico new file mode 100644 index 0000000..e144137 Binary files /dev/null and b/assets/icons/icon_256x256.ico differ diff --git a/assets/icons/icon_32x32.ico b/assets/icons/icon_32x32.ico new file mode 100644 index 0000000..90531ee Binary files /dev/null and b/assets/icons/icon_32x32.ico differ diff --git a/assets/icons/icon_48x48.ico b/assets/icons/icon_48x48.ico new file mode 100644 index 0000000..5bf9357 Binary files /dev/null and b/assets/icons/icon_48x48.ico differ diff --git a/assets/icons/icon_68x68.ico b/assets/icons/icon_68x68.ico new file mode 100644 index 0000000..733f9ad Binary files /dev/null and b/assets/icons/icon_68x68.ico differ diff --git a/bbb.txt b/bbb.txt new file mode 100644 index 0000000..3c29f40 --- /dev/null +++ b/bbb.txt @@ -0,0 +1 @@ +D:\@code\@demo\webview-bun-demo \ No newline at end of file diff --git a/bun.lock b/bun.lock new file mode 100644 index 0000000..1d958c0 --- /dev/null +++ b/bun.lock @@ -0,0 +1,32 @@ +{ + "lockfileVersion": 1, + "workspaces": { + "": { + "name": "webview-bun-demo", + "dependencies": { + "webview-bun": "^2.3.0", + }, + "devDependencies": { + "@types/bun": "latest", + }, + "peerDependencies": { + "typescript": "^5.0.0", + }, + }, + }, + "packages": { + "@types/bun": ["@types/bun@1.2.6", "", { "dependencies": { "bun-types": "1.2.6" } }, "sha512-fY9CAmTdJH1Llx7rugB0FpgWK2RKuHCs3g2cFDYXUutIy1QGiPQxKkGY8owhfZ4MXWNfxwIbQLChgH5gDsY7vw=="], + + "@types/node": ["@types/node@22.13.13", "", { "dependencies": { "undici-types": "~6.20.0" } }, "sha512-ClsL5nMwKaBRwPcCvH8E7+nU4GxHVx1axNvMZTFHMEfNI7oahimt26P5zjVCRrjiIWj6YFXfE1v3dEp94wLcGQ=="], + + "@types/ws": ["@types/ws@8.5.14", "", { "dependencies": { "@types/node": "*" } }, "sha512-bd/YFLW+URhBzMXurx7lWByOu+xzU9+kb3RboOteXYDfW+tr+JZa99OyNmPINEGB/ahzKrEuc8rcv4gnpJmxTw=="], + + "bun-types": ["bun-types@1.2.6", "", { "dependencies": { "@types/node": "*", "@types/ws": "~8.5.10" } }, "sha512-FbCKyr5KDiPULUzN/nm5oqQs9nXCHD8dVc64BArxJadCvbNzAI6lUWGh9fSJZWeDIRD38ikceBU8Kj/Uh+53oQ=="], + + "typescript": ["typescript@5.8.2", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-aJn6wq13/afZp/jT9QZmwEjDqqvSGp1VT5GVg+f/t6/oVyrgXM6BY1h9BRh/O5p3PlUPAe+WuiEZOmb/49RqoQ=="], + + "undici-types": ["undici-types@6.20.0", "", {}, "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg=="], + + "webview-bun": ["webview-bun@2.3.0", "", {}, "sha512-SYOksNzgjTajM+xhqdbhd1xzmCfDyqdmkLGSyZ5i30HRR5KTZJN6+cyE+OGCBFoPFBPmskUM3R99YXtQJqP7Qg=="], + } +} diff --git a/hidecmd.bat b/hidecmd.bat new file mode 100644 index 0000000..bcc1bb8 --- /dev/null +++ b/hidecmd.bat @@ -0,0 +1,23 @@ +@echo off +echo Looking for vswhere.exe... +set "vswhere=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" +if not exist "%vswhere%" set "vswhere=%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe" +if not exist "%vswhere%" ( + echo ERROR: Failed to find vswhere.exe + exit /b 1 +) +echo Found %vswhere% + +echo Looking for VC... +for /f "usebackq tokens=*" %%i in (`"%vswhere%" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do ( + set vc_dir=%%i +) +if not exist "%vc_dir%\Common7\Tools\vsdevcmd.bat" ( + echo ERROR: Failed to find VC tools x86/x64 + exit /b 1 +) +echo Found %vc_dir% + +call "%vc_dir%\Common7\Tools\vsdevcmd.bat" -arch=x64 -host_arch=x64 + +editbin /SUBSYSTEM:WINDOWS %1 \ No newline at end of file diff --git a/icon.ico b/icon.ico new file mode 100644 index 0000000..f9cb346 Binary files /dev/null and b/icon.ico differ diff --git a/icon.png b/icon.png new file mode 100644 index 0000000..f5bba78 Binary files /dev/null and b/icon.png differ diff --git a/main copy.ts b/main copy.ts new file mode 100644 index 0000000..0d485d8 --- /dev/null +++ b/main copy.ts @@ -0,0 +1,20 @@ +import { Webview, SizeHint } from "webview-bun"; +import fs from "node:fs"; +// 把html嵌入到单独可执行文件中,编译无需带ui.html +import html from "./ui.html" with { type: "text" }; +import path from "node:path"; +// 第一个参数是禁止开发者工具 SizeHint.FIXED是禁窗口最大化 +const webview = new Webview(false, { height: 480, width: 640, hint: SizeHint.NONE }); + +let counter = 0; +// 绑定前端button(increment,decrement)的事件 +webview.bind("count", (a) => counter += a); +// 绑定前端button(compute)的事件 +webview.bind("compute", (a, b) => a + b); +// 软件标题 +webview.title = "Bun App"; +fs.writeFileSync("./aaa.txt", import.meta.path) +fs.writeFileSync("./bbb.txt", process.cwd()) +const data = fs.readFileSync(path.resolve("./ui.html"), "utf-8").toString() +webview.setHTML(data); +webview.run(); \ No newline at end of file diff --git a/main.js.map b/main.js.map new file mode 100644 index 0000000..94476ce --- /dev/null +++ b/main.js.map @@ -0,0 +1,10 @@ +{ + "version": 3, + "sources": ["main.ts"], + "sourcesContent": [ + "import fs from \"node:fs\";\r\nimport path from \"node:path\";\r\n\r\nconst server = Bun.serve({\r\n fetch() {\r\n // return Response.json({ success: true });\r\n return new Response(\"