minista 2.0.0-alpha.2 → 2.0.0-alpha.3
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/vite.js +36 -1
- package/lib/index.html +1 -0
- package/package.json +1 -1
package/dist/vite.js
CHANGED
|
@@ -50,12 +50,16 @@ function virtualHtml() {
|
|
|
50
50
|
name: "vite-plugin-minista-virtual-html",
|
|
51
51
|
configureServer(server) {
|
|
52
52
|
return () => {
|
|
53
|
+
var _a, _b, _c, _d;
|
|
53
54
|
const ministaHtmlURL = new URL(path.resolve(__dirname + "/../lib/index.html"), import.meta.url);
|
|
54
55
|
const ministaHtml = fs.readFileSync(ministaHtmlURL, "utf8");
|
|
56
|
+
const assetTagStr = getAssetsTagStr((_b = (_a = server.config.inlineConfig.build) == null ? void 0 : _a.rollupOptions) == null ? void 0 : _b.input);
|
|
57
|
+
const ministaReplacedHtml = ministaHtml.replace("<!-- VIRTUAL_HTML_ASSETS_TAG -->", assetTagStr);
|
|
58
|
+
console.log((_d = (_c = server.config.inlineConfig.build) == null ? void 0 : _c.rollupOptions) == null ? void 0 : _d.input);
|
|
55
59
|
server.middlewares.use((req, res, next) => {
|
|
56
60
|
if (req.url.endsWith(".html")) {
|
|
57
61
|
res.statusCode = 200;
|
|
58
|
-
res.end(
|
|
62
|
+
res.end(ministaReplacedHtml);
|
|
59
63
|
return;
|
|
60
64
|
}
|
|
61
65
|
next();
|
|
@@ -64,6 +68,37 @@ function virtualHtml() {
|
|
|
64
68
|
}
|
|
65
69
|
};
|
|
66
70
|
}
|
|
71
|
+
function getAssetsTagStr(input) {
|
|
72
|
+
!input && "";
|
|
73
|
+
const tags = [];
|
|
74
|
+
if (typeof input === "string") {
|
|
75
|
+
const tag = getAssetsTag(input);
|
|
76
|
+
tags.push(tag);
|
|
77
|
+
} else if (Array.isArray(input) && input.length > 0) {
|
|
78
|
+
input.map((item) => {
|
|
79
|
+
const tag = getAssetsTag(item);
|
|
80
|
+
return tags.push(tag);
|
|
81
|
+
});
|
|
82
|
+
} else if (typeof input === "object") {
|
|
83
|
+
Object.values(input).map((item) => {
|
|
84
|
+
const tag = typeof item === "string" ? getAssetsTag(item) : "";
|
|
85
|
+
return tags.push(tag);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
const sortedTags = tags.sort((a, b) => a < b ? -1 : 1);
|
|
89
|
+
return sortedTags.join("\n");
|
|
90
|
+
}
|
|
91
|
+
function getAssetsTag(input) {
|
|
92
|
+
!input && "";
|
|
93
|
+
if (input.match(/\.(css|sass|scss)$/)) {
|
|
94
|
+
return `<link rel="stylesheet" href="${input}">`;
|
|
95
|
+
} else if (input.match(/\.(js|cjs|mjs|jsx|ts|tsx)$/)) {
|
|
96
|
+
return `<script defer src="${input}"><\/script>`;
|
|
97
|
+
} else {
|
|
98
|
+
console.log("Could not insert the entry [vite.build.rollupOptions.input] into the dev server.");
|
|
99
|
+
return "";
|
|
100
|
+
}
|
|
101
|
+
}
|
|
67
102
|
export {
|
|
68
103
|
defaultViteConfig,
|
|
69
104
|
getViteConfig,
|
package/lib/index.html
CHANGED