vite-pug-static-builder 1.1.1 → 1.1.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.
@@ -1 +1 @@
1
- {"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../src/serve.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAEjC,OAAO,KAAK,GAAG,MAAM,KAAK,CAAA;AAC1B,OAAO,KAAK,EAAE,MAAM,EAAiB,OAAO,EAAE,MAAM,MAAM,CAAA;AAE1D,OAAO,KAAK,SAAS,MAAM,WAAW,CAAA;AAKtC;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,oBAAoB;IACpB,QAAQ,CAAC,OAAO,CAAC,EAAE,GAAG,CAAC,OAAO,CAAA;IAC9B,sBAAsB;IACtB,QAAQ,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC,YAAY,CAAA;IAClC,4BAA4B;IAC5B,QAAQ,CAAC,aAAa,CAAC,EAAE,SAAS,CAAC,IAAI,CAAA;IACvC,2BAA2B;IAC3B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAC1B;AAED;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,CACvB,GAAG,EAAE,OAAO,CAAC,eAAe,EAC5B,GAAG,EAAE,IAAI,CAAC,cAAc,EACxB,IAAI,EAAE,OAAO,CAAC,YAAY,KACvB,IAAI,GAAG,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,cAAc,CAAC,CAAA;AA+FrE;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,GAAI,WAAW,aAAa,KAAG,MAsD7D,CAAA"}
1
+ {"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../src/serve.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAEjC,OAAO,KAAK,GAAG,MAAM,KAAK,CAAA;AAC1B,OAAO,KAAK,EAAE,MAAM,EAAiB,OAAO,EAAE,MAAM,MAAM,CAAA;AAE1D,OAAO,KAAK,SAAS,MAAM,WAAW,CAAA;AAKtC;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,oBAAoB;IACpB,QAAQ,CAAC,OAAO,CAAC,EAAE,GAAG,CAAC,OAAO,CAAA;IAC9B,sBAAsB;IACtB,QAAQ,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC,YAAY,CAAA;IAClC,4BAA4B;IAC5B,QAAQ,CAAC,aAAa,CAAC,EAAE,SAAS,CAAC,IAAI,CAAA;IACvC,2BAA2B;IAC3B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAC1B;AAED;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,CACvB,GAAG,EAAE,OAAO,CAAC,eAAe,EAC5B,GAAG,EAAE,IAAI,CAAC,cAAc,EACxB,IAAI,EAAE,OAAO,CAAC,YAAY,KACvB,IAAI,GAAG,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,cAAc,CAAC,CAAA;AA+FrE;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,GAAI,WAAW,aAAa,KAAG,MAuE7D,CAAA"}
package/dist/serve.js CHANGED
@@ -85,39 +85,47 @@ export const vitePluginPugServe = (settings) => {
85
85
  server = _server;
86
86
  server.middlewares.use(createMiddleware(settings ?? {}, server));
87
87
  },
88
- handleHotUpdate(context) {
89
- const fileModules = server.moduleGraph.getModulesByFile(context.file);
90
- if (fileModules) {
91
- for (const fileModule of fileModules) {
92
- for (const importer of fileModule.importers) {
93
- if (importer.file && path.extname(importer.file) === '.pug') {
94
- server.moduleGraph.invalidateModule(importer);
95
- }
96
- }
97
- }
98
- }
99
- // Pugファイル自体が変更された場合の処理
100
- if (path.extname(context.file) === '.pug') {
88
+ // Vite 7の新しいhotUpdateフックを使用してより効率的な処理を実装
89
+ hotUpdate(context) {
90
+ const { file, timestamp } = context;
91
+ const { environment } = this;
92
+ // Pugファイル自体が変更された場合
93
+ if (path.extname(file) === '.pug') {
101
94
  // 対応するHTMLモジュールのURLを生成
102
- const parsedPath = path.parse(context.file);
95
+ const parsedPath = path.parse(file);
103
96
  const htmlUrl = path.posix.format({
104
97
  dir: parsedPath.dir.replace(server.config.root, '').replace(/\\/g, '/'),
105
98
  name: parsedPath.name,
106
99
  ext: '.html',
107
100
  });
108
- // HTMLモジュールを取得して無効化
109
- const htmlModule = server.moduleGraph.getModuleById(htmlUrl) ||
110
- server.moduleGraph.urlToModuleMap.get(htmlUrl);
111
- if (htmlModule) {
112
- // transformResultを明示的にクリアして確実に再コンパイルを実行
113
- htmlModule.transformResult = null;
114
- server.moduleGraph.invalidateModule(htmlModule);
101
+ // Environment APIを使用してモジュールを取得・無効化(非同期処理を修正)
102
+ environment.moduleGraph.getModuleByUrl(htmlUrl).then((htmlModule) => {
103
+ if (htmlModule) {
104
+ // モジュールを適切に無効化(Vite 7の新しいAPI)
105
+ environment.moduleGraph.invalidateModule(htmlModule, new Set(), timestamp, true // HMRフラグを明示的にtrue
106
+ );
107
+ }
108
+ }).catch(() => {
109
+ // モジュールが見つからない場合は無視
110
+ });
111
+ }
112
+ // 従来のファイルモジュール無効化処理
113
+ const fileModules = environment.moduleGraph.getModulesByFile(file);
114
+ if (fileModules) {
115
+ const invalidatedModules = new Set(); // 型を明示的に指定
116
+ for (const fileModule of fileModules) {
117
+ for (const importer of fileModule.importers) {
118
+ if (importer.file && path.extname(importer.file) === '.pug') {
119
+ environment.moduleGraph.invalidateModule(importer, invalidatedModules, timestamp, true);
120
+ }
121
+ }
115
122
  }
116
123
  }
117
124
  // リロード設定に基づいてフルリロードを実行
118
125
  if (reload !== false) {
119
- context.server.ws.send({ type: 'full-reload' });
126
+ environment.hot.send({ type: 'full-reload' });
120
127
  }
121
128
  },
129
+ // 古いhandleHotUpdateフックは削除(Vite 7では非推奨)
122
130
  };
123
131
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-pug-static-builder",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "Vite + Pugを使用した静的サイトビルダー - 複数のPugファイルを静的HTMLとしてビルドするViteプラグイン",
5
5
  "author": "maigo999",
6
6
  "license": "MIT",
@@ -64,7 +64,7 @@
64
64
  "fs-extra": "^11.3.0",
65
65
  "rimraf": "^6.0.1",
66
66
  "typescript": "^5.6.3",
67
- "vite": "^7.0.0",
67
+ "vite": "^7.0.5",
68
68
  "vitest": "^3.2.1"
69
69
  }
70
70
  }