@pubinfo/vite 2.0.11 → 2.0.12

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/index.js +18 -9
  2. package/package.json +2 -1
package/dist/index.js CHANGED
@@ -7,6 +7,7 @@ import { dirname, join, posix, relative, resolve } from "node:path";
7
7
  import vue from "@vitejs/plugin-vue";
8
8
  import vueJsx from "@vitejs/plugin-vue-jsx";
9
9
  import boxen from "boxen";
10
+ import MagicString from "magic-string";
10
11
  import fg from "fast-glob";
11
12
  import { merge } from "lodash-es";
12
13
  import picomatch from "picomatch";
@@ -134,15 +135,22 @@ function createInjectAuto(options) {
134
135
  else if (typeof lib.entry === "object") entryFiles = Object.values(lib.entry).map(toAbs);
135
136
  },
136
137
  transform(code, _id) {
137
- if (entryFiles.includes(_id)) return `
138
+ if (entryFiles.includes(_id)) {
139
+ const s = new MagicString(code);
140
+ const injectCode = `
138
141
  import { defineRouteModule, defineIconModule } from 'pubinfo';
139
142
  import modules from 'virtual:pubinfo-resolver';
140
143
 
141
144
  defineRouteModule('${id}', modules.pages);
142
145
  defineIconModule('${id}', modules.icons);
143
146
 
144
- ${code}
145
147
  `;
148
+ s.prepend(injectCode);
149
+ return {
150
+ code: s.toString(),
151
+ map: s.generateMap({ hires: true })
152
+ };
153
+ }
146
154
  }
147
155
  };
148
156
  }
@@ -226,14 +234,13 @@ function libResolverPlugin(options) {
226
234
  files: []
227
235
  };
228
236
  const base = getPatternBase(pattern);
229
- const imports = files.map((file) => {
230
- const absPath = normalizePath$1(file);
231
- const relToBase = normalizePath$1(relative(resolve(base), file));
232
- return `"${posix.join(base, relToBase)}": () => import("${absPath}")`;
233
- }).join(",\n");
234
237
  return {
235
238
  key,
236
- content: `"${key}": {\n${imports}\n }`,
239
+ content: `"${key}": {\n${files.map((file) => {
240
+ const absPath = normalizePath$1(file);
241
+ const relToBase = normalizePath$1(relative(resolve(base), file));
242
+ return `"${posix.join(base, relToBase)}": () => import("${absPath}")`;
243
+ }).join(",\n")}\n }`,
237
244
  files
238
245
  };
239
246
  } catch (error) {
@@ -300,10 +307,12 @@ function createVirtualInspectorPlugin(options = {}) {
300
307
  });
301
308
  },
302
309
  async resolveId(importee) {
310
+ if (config?.command !== "serve") return null;
303
311
  if (importee === virtualModuleId) return resolve(inspectorPath, "load.js");
304
312
  return null;
305
313
  },
306
314
  async load(id) {
315
+ if (config?.command !== "serve") return null;
307
316
  if (id.includes("load.js") && id.includes(inspectorPath)) {
308
317
  if (!enabled) return "export default {};";
309
318
  const filePath = resolve(inspectorPath, "load.js");
@@ -316,7 +325,7 @@ function createVirtualInspectorPlugin(options = {}) {
316
325
  return null;
317
326
  },
318
327
  transformIndexHtml(html) {
319
- if (!enabled) return;
328
+ if (!enabled || config?.command !== "serve") return;
320
329
  return {
321
330
  html,
322
331
  tags: [{
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pubinfo/vite",
3
3
  "type": "module",
4
- "version": "2.0.11",
4
+ "version": "2.0.12",
5
5
  "exports": {
6
6
  ".": {
7
7
  "types": "./dist/index.d.ts",
@@ -34,6 +34,7 @@
34
34
  "fs-extra": "^11.3.0",
35
35
  "jszip": "^3.10.1",
36
36
  "lodash-es": "^4.17.21",
37
+ "magic-string": "^0.30.19",
37
38
  "picomatch": "^4.0.3",
38
39
  "pkg-types": "^2.3.0",
39
40
  "rolldown-vite": "^7.1.2",