Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace NODE_ENV during Vite build #6644

Merged
merged 10 commits into from
Jan 23, 2024
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
- Prevent the use of pinTags + minInstances on the same function, as the features are not mutually compatible (#6684)
- Add force flag to delete backend (#6635).
- Use framework build target in Vite builds (#6643).
- Use framework build target in NODE_ENV for production Vite builds (#6644)
9 changes: 9 additions & 0 deletions src/frameworks/vite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { existsSync } from "fs";
import { copy, pathExists } from "fs-extra";
import { join } from "path";
const stripAnsi = require("strip-ansi");

Check warning on line 6 in src/frameworks/vite/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value

Check warning on line 6 in src/frameworks/vite/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Require statement not part of import statement
import { FrameworkType, SupportLevel } from "../interfaces";
import { promptOnce } from "../../prompt";
import {
Expand All @@ -21,11 +21,11 @@

export const DEFAULT_BUILD_SCRIPT = ["vite build", "tsc && vite build"];

export const initViteTemplate = (template: string) => async (setup: any, config: any) =>

Check warning on line 24 in src/frameworks/vite/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type

Check warning on line 24 in src/frameworks/vite/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
await init(setup, config, template);

export async function init(setup: any, config: any, baseTemplate: string = "vanilla") {

Check warning on line 27 in src/frameworks/vite/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing return type on function

Check warning on line 27 in src/frameworks/vite/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing JSDoc comment

Check warning on line 27 in src/frameworks/vite/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type

Check warning on line 27 in src/frameworks/vite/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type

Check warning on line 27 in src/frameworks/vite/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Type string trivially inferred from a string literal, remove type annotation
const template = await promptOnce({

Check warning on line 28 in src/frameworks/vite/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
type: "list",
default: "JavaScript",
message: "What language would you like to use?",
Expand Down Expand Up @@ -86,9 +86,18 @@
// SvelteKit uses process.cwd() unfortunately, chdir
const cwd = process.cwd();
process.chdir(root);

const originalNodeEnv = process.env.NODE_ENV;
// @ts-expect-error - NODE_ENV is `development` when building for production
// temporarily replace with target during build
process.env.NODE_ENV = target;

await build({ root, mode: target });
process.chdir(cwd);

// @ts-expect-error - restore NODE_ENV after build
process.env.NODE_ENV = originalNodeEnv;

return { rewrites: [{ source: "**", destination: "/index.html" }] };
}

Expand Down