@yoamigo.com/core 1.4.2 → 1.5.0
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.
- package/dist/plugin.js +67 -10
- package/package.json +1 -1
package/dist/plugin.js
CHANGED
|
@@ -2,10 +2,18 @@
|
|
|
2
2
|
import react from "@vitejs/plugin-react";
|
|
3
3
|
import path from "path";
|
|
4
4
|
import { createRequire } from "module";
|
|
5
|
+
import { execFileSync } from "child_process";
|
|
6
|
+
import { existsSync, readFileSync, writeFileSync } from "fs";
|
|
7
|
+
import { fileURLToPath } from "url";
|
|
5
8
|
var require2 = createRequire(import.meta.url);
|
|
6
9
|
function yoamigoPlugin(options = {}) {
|
|
7
10
|
const templateDir = process.cwd();
|
|
8
11
|
const resolveFromTemplate = (relativePath) => path.resolve(templateDir, relativePath);
|
|
12
|
+
let tablerIconsPath;
|
|
13
|
+
try {
|
|
14
|
+
tablerIconsPath = path.dirname(require2.resolve("@tabler/icons-react/package.json"));
|
|
15
|
+
} catch {
|
|
16
|
+
}
|
|
9
17
|
return [
|
|
10
18
|
// Content HMR plugin - enables hot reloading of content.ts without full page refresh
|
|
11
19
|
{
|
|
@@ -46,12 +54,6 @@ if (import.meta.hot) {
|
|
|
46
54
|
name: "yoamigo:config",
|
|
47
55
|
config(config, { mode }) {
|
|
48
56
|
const isProd = mode === "production";
|
|
49
|
-
let tablerIconsPath;
|
|
50
|
-
try {
|
|
51
|
-
tablerIconsPath = path.dirname(require2.resolve("@tabler/icons-react/package.json"));
|
|
52
|
-
} catch {
|
|
53
|
-
console.warn("[yoamigo] @tabler/icons-react not found - icon loading may fail");
|
|
54
|
-
}
|
|
55
57
|
const aliasArray = [
|
|
56
58
|
// Production aliases must come FIRST for priority
|
|
57
59
|
...isProd ? [
|
|
@@ -97,11 +99,12 @@ if (import.meta.hot) {
|
|
|
97
99
|
// Ensure single React instance across all packages (prevents "Invalid hook call" errors)
|
|
98
100
|
dedupe: ["react", "react-dom"]
|
|
99
101
|
},
|
|
100
|
-
//
|
|
101
|
-
//
|
|
102
|
+
// Pre-bundle React to ensure a single instance across all packages.
|
|
103
|
+
// @tabler/icons-react is NOT included here — it's resolved via the alias
|
|
104
|
+
// above to core's node_modules, so Vite doesn't need to find it in the
|
|
105
|
+
// template's own node_modules (which would fail with pnpm strict linking).
|
|
102
106
|
optimizeDeps: {
|
|
103
107
|
include: [
|
|
104
|
-
...tablerIconsPath ? ["@tabler/icons-react"] : [],
|
|
105
108
|
"react",
|
|
106
109
|
"react-dom"
|
|
107
110
|
]
|
|
@@ -154,7 +157,61 @@ if (import.meta.hot) {
|
|
|
154
157
|
}
|
|
155
158
|
};
|
|
156
159
|
}
|
|
157
|
-
}
|
|
160
|
+
},
|
|
161
|
+
// Icon auto-registration plugin — in production builds, automatically scans
|
|
162
|
+
// template source for icon usage and generates a registration file so that
|
|
163
|
+
// the prod icon registry has all needed icons without manual setup.
|
|
164
|
+
(function yoamigoIconsPlugin() {
|
|
165
|
+
let isProd = false;
|
|
166
|
+
const pluginDir = path.dirname(fileURLToPath(import.meta.url));
|
|
167
|
+
const iconScannerPath = path.resolve(pluginDir, "../bin/icon-scanner.cjs");
|
|
168
|
+
return {
|
|
169
|
+
name: "yoamigo:icons",
|
|
170
|
+
configResolved(config) {
|
|
171
|
+
isProd = config.command === "build";
|
|
172
|
+
},
|
|
173
|
+
buildStart() {
|
|
174
|
+
if (!isProd) return;
|
|
175
|
+
const srcDir = path.resolve(templateDir, "src");
|
|
176
|
+
const outFile = path.resolve(templateDir, "src/icons.generated.ts");
|
|
177
|
+
console.log("[yoamigo:icons] Scanning icons for production build...");
|
|
178
|
+
try {
|
|
179
|
+
execFileSync("node", [iconScannerPath, "-src", srcDir, "-out", outFile], {
|
|
180
|
+
stdio: "inherit",
|
|
181
|
+
cwd: templateDir
|
|
182
|
+
});
|
|
183
|
+
if (tablerIconsPath) {
|
|
184
|
+
let generated = readFileSync(outFile, "utf-8");
|
|
185
|
+
const lines = generated.split("\n");
|
|
186
|
+
const filtered = lines.filter((line) => {
|
|
187
|
+
const match = line.match(
|
|
188
|
+
/import\('@tabler\/icons-react\/dist\/esm\/icons\/(\w+)\.mjs'\)/
|
|
189
|
+
);
|
|
190
|
+
if (!match) return true;
|
|
191
|
+
const iconFile = path.join(tablerIconsPath, "dist", "esm", "icons", `${match[1]}.mjs`);
|
|
192
|
+
if (!existsSync(iconFile)) {
|
|
193
|
+
console.warn(`[yoamigo:icons] Skipping "${match[1]}" \u2014 not found in @tabler/icons-react`);
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
return true;
|
|
197
|
+
});
|
|
198
|
+
writeFileSync(outFile, filtered.join("\n"), "utf-8");
|
|
199
|
+
}
|
|
200
|
+
console.log("[yoamigo:icons] Icon registration file generated");
|
|
201
|
+
} catch (err) {
|
|
202
|
+
console.error("[yoamigo:icons] Icon scanner failed:", err);
|
|
203
|
+
throw err;
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
transform(code, id) {
|
|
207
|
+
if (!isProd) return;
|
|
208
|
+
if (!id.match(/\/main\.tsx?$/) && !id.match(/\\main\.tsx?$/)) return;
|
|
209
|
+
const injection = `import './icons.generated';
|
|
210
|
+
`;
|
|
211
|
+
return { code: injection + code, map: null };
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
})()
|
|
158
215
|
];
|
|
159
216
|
}
|
|
160
217
|
var plugin_default = yoamigoPlugin;
|