diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a0ca0c1..b928c59 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -27,7 +27,7 @@ jobs: - name: Rename artifact run: - mv download/plugin.zip download/${{ github.event.repository.name }}-${{ github.ref_name }}.zip + unzip download/plugin.zip -d download && rm download/plugin.zip - name: Create release uses: 'marvinpinto/action-automatic-releases@latest' diff --git a/package.json b/package.json index a2d2763..0f9926c 100644 --- a/package.json +++ b/package.json @@ -6,12 +6,12 @@ "scripts": { "dev": "npm run clear && cross-env NODE_ENV=development run-p dev:*", "dev:js": "npm run build:js -- --mode development", - "dev:web": "vite dev --config vite.config.window.ts", + "dev:web": "vite dev --config vite.config.web.ts", "build": "cross-env NODE_ENV=production run-s clear build:web build:js ", "build:js": "vite build --config vite.config.ts", - "build:web": "vite build --config vite.config.window.ts", + "build:web": "vite build --config vite.config.web.ts", "release": "run-s build pack", - "pack": "rimraf plugin.zip && bestzip plugin.zip window main.js styles.css manifest.json", + "pack": "rimraf plugin.zip && bestzip plugin.zip main.js styles.css manifest.json", "clear": "rimraf assets window main.js styles.css", "version": "node version-bump.mjs && git add manifest.json versions.json", "typecheck": "tsc --noEmit" diff --git a/src/env.d.ts b/src/env.d.ts index 4bf2977..d91fc31 100644 --- a/src/env.d.ts +++ b/src/env.d.ts @@ -1,6 +1,7 @@ /// declare const __DEV__: boolean +declare const __MINI_TRACKER_HTML__: string interface ImportMetaEnv { readonly VITE_DEV_SERVER_URL: string diff --git a/src/window/mini-tracker/mini-tracker.ts b/src/window/mini-tracker/mini-tracker.ts index 7e9ffa4..0457d4e 100644 --- a/src/window/mini-tracker/mini-tracker.ts +++ b/src/window/mini-tracker/mini-tracker.ts @@ -74,13 +74,7 @@ export class MiniTracker { if (__DEV__) { this.win.loadURL(import.meta.env.VITE_DEV_SERVER_URL + 'window/mini-tracker/index.html') } else { - const filePath = normalizePath(`${windowFolderPath}/mini-tracker/index.html`) - - const fs = require('node:fs/promises') - const buffer = await fs.readFile(filePath) - const content = buffer.toString('utf8') - - this.win.loadURL(`data:text/html;charset=UTF-8,${encodeURIComponent(content)}`) + this.win.loadURL(`data:text/html;charset=UTF-8,__MINI_TRACKER_HTML__`) } this.tracker.addObserver(this.trackerObserver) diff --git a/vite.config.ts b/vite.config.ts index c9f070e..a114bd2 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -6,14 +6,20 @@ import { isDev } from './scripts/utils' import { preact } from '@preact/preset-vite' import UnoCSS from 'unocss/vite' import presetWind from 'unocss/preset-wind' +import fs from 'fs' // import react from '@vitejs/plugin' const banner = `/* -THIS IS A GENERATED/BUNDLED FILE BY ESBUILD +THIS IS A GENERATED/BUNDLED FILE BY ROLLUP if you want to view the source, please visit the github repository of this plugin */ ` +const readMiniTrackerHtml = () => { + const html = fs.readFileSync('window/mini-tracker/index.html', 'utf-8') + return html +} + // https://vitejs.dev/config/ export default defineConfig({ esbuild: { @@ -21,6 +27,7 @@ export default defineConfig({ }, define: { __DEV__: isDev, + __MINI_TRACKER_HTML__: isDev ? '' : encodeURIComponent(readMiniTrackerHtml()), 'process.env.NODE_ENV': JSON.stringify(isDev ? 'development' : 'production'), }, build: { @@ -29,9 +36,11 @@ export default defineConfig({ entry: 'src/main.ts', formats: ['cjs'], }, - watch: isDev ? { - buildDelay: 3000 - } : undefined, + watch: isDev + ? { + buildDelay: 3000, + } + : undefined, outDir: '.', emptyOutDir: false, rollupOptions: { diff --git a/vite.config.window.ts b/vite.config.web.ts similarity index 100% rename from vite.config.window.ts rename to vite.config.web.ts