Skip to content

Commit

Permalink
fix: unable to compile console and uc on Windows platform (#4877)
Browse files Browse the repository at this point in the history
#### What type of PR is this?

/kind bug
/area console
/milestone 2.11.x

#### What this PR does / why we need it:

修复在 Windows 平台下无法正常启动 Console 服务以及无法正常编译的问题。

<img width="1124" alt="图片" src="https://github.com/halo-dev/halo/assets/21301288/55edd00a-8e71-437e-8889-0fe4a43bb40b">

#### Which issue(s) this PR fixes:

Fixes #4874

#### Special notes for your reviewer:

在 Windows 平台下测试 `pnpm dev` 和 `pnpm build`,检查是否能够正常运行。

#### Does this PR introduce a user-facing change?

```release-note
None
```
  • Loading branch information
ruibaby committed Nov 20, 2023
1 parent 747cab3 commit fbc9045
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions console/src/vite/config-builder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fileURLToPath, URL } from "url";
import { fileURLToPath } from "url";
import fs from "fs";
import { defineConfig, type Plugin } from "vite";
import Vue from "@vitejs/plugin-vue";
Expand All @@ -7,6 +7,7 @@ import { VitePWA } from "vite-plugin-pwa";
import Icons from "unplugin-icons/vite";
import { setupLibraryExternal } from "./library-external";
import GzipPlugin from "rollup-plugin-gzip";
import path from "path";

interface Options {
base: string;
Expand Down Expand Up @@ -49,6 +50,9 @@ export function createViteConfig(options: Options) {

const { base, entryFile, port, outDir, plugins } = options;

const currentFileDir = path.dirname(fileURLToPath(import.meta.url));
const rootDir = path.resolve(currentFileDir, "../..");

return defineConfig({
base,
plugins: [
Expand All @@ -58,9 +62,9 @@ export function createViteConfig(options: Options) {
],
resolve: {
alias: {
"@": fileURLToPath(new URL("/src", import.meta.url)),
"@console": fileURLToPath(new URL("/console-src", import.meta.url)),
"@uc": fileURLToPath(new URL("/uc-src", import.meta.url)),
"@": path.resolve(rootDir, "src"),
"@console": path.resolve(rootDir, "console-src"),
"@uc": path.resolve(rootDir, "uc-src"),
},
},
server: {
Expand All @@ -70,7 +74,7 @@ export function createViteConfig(options: Options) {
},
},
build: {
outDir: fileURLToPath(new URL(outDir, import.meta.url)),
outDir: path.resolve(rootDir, outDir),
emptyOutDir: true,
chunkSizeWarningLimit: 2048,
},
Expand Down

0 comments on commit fbc9045

Please sign in to comment.