@maoyugames/phaser-framework 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/cli/index.js +29 -16
  2. package/package.json +1 -1
package/dist/cli/index.js CHANGED
@@ -236,7 +236,15 @@ function createPlatformConfig(platform, opts) {
236
236
  __FRAMEWORK_VERSION__: JSON.stringify(frameworkVersion)
237
237
  },
238
238
  resolve: {
239
- alias: createAlias(projectRoot)
239
+ alias: createAlias(projectRoot),
240
+ // 去重 phaser:避免框架包与业务解析到不同 phaser 实例
241
+ dedupe: ["phaser"]
242
+ },
243
+ // dev 模式必须预打包 phaser(及框架包)为带 default 导出的 ESM,
244
+ // 否则 vite dev 下 `import Phaser from 'phaser'` 报
245
+ // "phaser does not provide an export named 'default'"(build 模式 rollup 自带 CJS 互操作,不受影响)。
246
+ optimizeDeps: {
247
+ include: ["phaser", "@maoyugames/phaser-framework"]
240
248
  },
241
249
  esbuild: {
242
250
  // 兼容低端 webview / 小游戏 JS 引擎
@@ -1043,27 +1051,25 @@ async function runDev(target) {
1043
1051
  const config = await loadPlatformConfig(ctx);
1044
1052
  const vite = await loadViteFromRoot(ctx.root);
1045
1053
  const cache = cacheDir2(ctx.root);
1046
- fse4.ensureDirSync(cache);
1047
1054
  const hash = randomBytes(4).toString("hex");
1048
- const entryFileName = `main.${platform}.${hash}.ts`;
1049
- const entryPath = join(cache, entryFileName);
1050
- const htmlName = `index.${platform}.${hash}.html`;
1051
- const htmlPath = join(cache, htmlName);
1055
+ const runDir = join(cache, `dev-${platform}-${hash}`);
1056
+ fse4.ensureDirSync(runDir);
1057
+ const entryFileName = `main.${platform}.ts`;
1058
+ const entryPath = join(runDir, entryFileName);
1059
+ const htmlPath = join(runDir, "index.html");
1052
1060
  fse4.writeFileSync(entryPath, renderEntry({ platform, projectRoot: ctx.root }), "utf-8");
1053
1061
  fse4.writeFileSync(htmlPath, renderHtmlShell2(platform, config, `./${entryFileName}`), "utf-8");
1054
1062
  const cleanup = () => {
1055
- for (const f of [entryPath, htmlPath]) {
1056
- try {
1057
- fse4.removeSync(f);
1058
- } catch {
1059
- }
1063
+ try {
1064
+ fse4.removeSync(runDir);
1065
+ } catch {
1060
1066
  }
1061
1067
  };
1062
1068
  try {
1063
1069
  const server = await vite.createServer({
1064
- // root 设为缓存目录(临时 HTML 所在),入口页直接是 /index.<p>.<hash>.html;
1065
- // alias/publicDir 用绝对路径不受影响
1066
- root: cache,
1070
+ // root 设为本次 dev 的独立子目录(其根有 index.html),浏览器打开 / 即入口页;
1071
+ // alias/publicDir 用绝对路径不受 root 影响
1072
+ root: runDir,
1067
1073
  base: "/",
1068
1074
  configFile: false,
1069
1075
  define: {
@@ -1075,7 +1081,14 @@ async function runDev(target) {
1075
1081
  alias: [
1076
1082
  { find: /^@game$/, replacement: resolve(ctx.root, "src/game") },
1077
1083
  { find: /^@game\//, replacement: resolve(ctx.root, "src/game") + "/" }
1078
- ]
1084
+ ],
1085
+ // 去重 phaser,避免框架包与业务解析到不同实例
1086
+ dedupe: ["phaser"]
1087
+ },
1088
+ // 必须预打包 phaser(及框架包)为带 default 导出的 ESM,
1089
+ // 否则 dev 下 `import Phaser from 'phaser'` 报 "does not provide an export named 'default'"。
1090
+ optimizeDeps: {
1091
+ include: ["phaser", "@maoyugames/phaser-framework"]
1079
1092
  },
1080
1093
  publicDir: resolve(ctx.root, "src/game/public"),
1081
1094
  server: { open: false }
@@ -1084,7 +1097,7 @@ async function runDev(target) {
1084
1097
  const info = server.resolvedUrls;
1085
1098
  const url = info?.local?.[0] ?? "http://localhost:5173/";
1086
1099
  console.log(pc4.green(pc4.bold(`\u25B6 [${platform}] dev server \u5C31\u7EEA`)));
1087
- console.log(` \u6253\u5F00:${pc4.cyan(url + htmlName)}`);
1100
+ console.log(` \u6253\u5F00:${pc4.cyan(url)}`);
1088
1101
  console.log(pc4.gray(" (Ctrl+C \u9000\u51FA,\u4E34\u65F6\u5165\u53E3\u4F1A\u81EA\u52A8\u6E05\u7406)"));
1089
1102
  const onExit = async () => {
1090
1103
  cleanup();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maoyugames/phaser-framework",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "多平台 Phaser 游戏框架:业务/底层分离,HTTP/WebSocket/KCP,Web/TikTok/微信/Facebook/App 隔离打包",
5
5
  "type": "module",
6
6
  "license": "MIT",