Skip to content

Commit

Permalink
fix(vite): html transformation (#89)
Browse files Browse the repository at this point in the history
* fix(vite): html transformation

* fix(vite): html transformation

In some cases, such as adding a class to the `<head>` element in the `index.html`, would cause the Vite resource not being able to generate the `wing` environment object.

Also, stop opening the browser when Wing is running tests.
  • Loading branch information
skyrpex authored Feb 19, 2024
1 parent 41bf35e commit 6fd317d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion vite/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@winglibs/vite",
"version": "0.0.2",
"version": "0.0.3",
"description": "Wing resource that allows deploying a Vite application to the cloud",
"repository": {
"type": "git",
Expand Down
4 changes: 3 additions & 1 deletion vite/vite-cli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ if (command === "dev") {
})
);

server.openBrowser();
if (options.openBrowser) {
server.openBrowser();
}
} else if (command === "build") {
const resolvedConfig = await resolveConfig(config);
console.log(
Expand Down
8 changes: 4 additions & 4 deletions vite/vite-plugin.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ export const plugin = (options) => {
},
transformIndexHtml(html) {
return html.replace(
"<head>",
`<head>\n <script>window.${
"</head>",
` <script>window.${
options.publicEnvName
}=Object.freeze({meta:Object.freeze({env:${JSON.stringify(
}=Object.freeze({env:Object.freeze(${JSON.stringify(
options.publicEnv
)}})});</script>`
)})});</script>\n</head>`
);
},
async buildStart() {
Expand Down
2 changes: 2 additions & 0 deletions vite/vite.sim.w
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub class Vite_sim {
let cliFilename = Vite_sim.cliFilename();
let homeEnv = util.env("HOME");
let pathEnv = util.env("PATH");
let openBrowser = util.env("WING_IS_TEST") != "true";

new cloud.Service(inflight () => {
let url = Vite_sim.dev({
Expand All @@ -25,6 +26,7 @@ pub class Vite_sim {
cliFilename: cliFilename,
homeEnv: homeEnv,
pathEnv: pathEnv,
openBrowser: openBrowser,
});
state.set("url", url);
});
Expand Down

0 comments on commit 6fd317d

Please sign in to comment.