From d31f9ac0beaac606858b583c4086d558e673141f Mon Sep 17 00:00:00 2001 From: Neko Ayaka Date: Wed, 10 Jul 2024 22:35:20 +0800 Subject: [PATCH] chore: better unbuild hook for copy and removal Signed-off-by: Neko Ayaka --- build.config.ts | 19 ++++++++++++++----- cspell.config.yaml | 3 +++ package.json | 4 +--- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/build.config.ts b/build.config.ts index a0ac953..09b205e 100644 --- a/build.config.ts +++ b/build.config.ts @@ -1,6 +1,10 @@ +import { exec } from 'node:child_process' +import { promisify } from 'node:util' import { defineBuildConfig } from 'unbuild' import builtins from 'builtin-modules' +const execAsync = promisify(exec) + export default defineBuildConfig({ outDir: './dist', sourcemap: true, @@ -20,11 +24,6 @@ export default defineBuildConfig({ '@lezer/common', '@lezer/highlight', '@lezer/lr', - // UnoCSS - '@iconify/utils/lib/loader/fs', - '@iconify/utils/lib/loader/install-pkg', - '@iconify/utils/lib/loader/node-loader', - '@iconify/utils/lib/loader/node-loaders', // Builtins ...builtins, ], @@ -44,4 +43,14 @@ export default defineBuildConfig({ // by esbuild inlineDependencies: true, }, + hooks: { + 'build:before': async () => { + await execAsync('rm -rf ./main.js') + await execAsync('rm -rf ./main.js.map') + }, + 'build:done': async () => { + await execAsync('cp ./dist/main.js ./main.js') + await execAsync('cp ./dist/main.js.map ./main.js.map') + }, + }, }) diff --git a/cspell.config.yaml b/cspell.config.yaml index 96a7c12..48f942e 100644 --- a/cspell.config.yaml +++ b/cspell.config.yaml @@ -5,9 +5,12 @@ dictionaries: [] words: - antfu - codemirror + - collab + - lezer - nolebase - Nólëbase - ofetch + - unocss - vueuse ignoreWords: [] import: [] diff --git a/package.json b/package.json index 81bc6bf..2e6574f 100644 --- a/package.json +++ b/package.json @@ -26,9 +26,7 @@ "dist" ], "scripts": { - "cleanup": "rm -rf ./main.js && rm -rf ./main.js.map", - "build": "unbuild && pnpm run cleanup && pnpm run copy", - "copy": "cp ./dist/main.js ./main.js && cp ./dist/main.js.map ./main.js.map", + "build": "unbuild", "lint": "eslint --cache ." }, "devDependencies": {