Browse Source

fix(vite): 仅生产环境 drop console,避免开发时误判场景未执行

- page_00_global: 用 logger 替代 console 便于与 Logger 级别配合

Made-with: Cursor
master
npmrun 3 weeks ago
parent
commit
8030b00ab0
  1. 44
      src/stages/_global/page_00_global.ts
  2. 7
      vite.config.ts

44
src/stages/_global/page_00_global.ts

@ -0,0 +1,44 @@
import { logger } from "@/core/Logger";
import { SceneType } from "@/enums/SceneType";
import { BaseScene } from "@/scene/BaseScene";
import { Assets, Container } from "pixi.js";
export default class Global extends BaseScene {
stage: Container = new Container();
constructor() {
super("00_global", SceneType.Resident);
logger.debug("Resident scene 00_global constructed");
}
async loadBundle(): Promise<void> {
Assets.add({ alias: "btn-bga", src: "/assets/images/button_square_depth_gloss.png" });
Assets.add({ alias: "btn-bg-press", src: "/assets/images/button_square_depth_gradient.png" });
await Assets.load("btn-bga");
await Assets.load("btn-bg-press");
}
async layout(): Promise<void> {
this.stage.sortableChildren = true;
this.stage.zIndex = 9999;
// const btnBg = Assets.get<Texture>("btn-bga");
// const btnBgPress = Assets.get<Texture>("btn-bg-press");
// this.btn = new Button({
// text: "全局",
// bg: btnBg,
// pressBg: btnBgPress,
// position: () => position.get("center", "center", { y: 100, x: 0 }),
// onClick: () => {
// console.log("Button clicked");
// },
// });
// this.stage.addChild(this.btn.getView());
}
onLoad(): void {
logger.info("Resident scene 00_global onLoad");
}
onUnLoad(): void {
}
}

7
vite.config.ts

@ -1,7 +1,7 @@
import { defineConfig } from "vite"; import { defineConfig } from "vite";
import tsconfigPaths from "vite-tsconfig-paths"; import tsconfigPaths from "vite-tsconfig-paths";
export default defineConfig({ export default defineConfig(({ mode }) => ({
build: { build: {
rollupOptions: { rollupOptions: {
output: { output: {
@ -21,8 +21,9 @@ export default defineConfig({
}, },
minify: "esbuild", minify: "esbuild",
}, },
/** 仅在生产去掉 console;开发时保留,否则常驻场景等 console 调试看起来像「没执行」 */
esbuild: { esbuild: {
drop: ["console", "debugger"], drop: mode === "production" ? (["console", "debugger"] as const) : [],
}, },
plugins: [tsconfigPaths()], plugins: [tsconfigPaths()],
}); }));

Loading…
Cancel
Save