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

respect --mode, and remove server, prod and mode from $app/env #5602

Merged
merged 11 commits into from
Jul 20, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/kit/src/vite/build/build_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export class Server {
/**
* @param {{
* cwd: string;
* config: import('types').ValidatedConfig
* config: import('types').ValidatedConfig;
Rich-Harris marked this conversation as resolved.
Show resolved Hide resolved
* vite_config_env: import('vite').ConfigEnv
* manifest_data: import('types').ManifestData
* build_dir: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/vite/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export async function get_vite_config(config_env) {
if (!config) {
throw new Error('Could not load Vite config');
}
return config;
return { ...config, mode: config_env.mode };
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/test/apps/options/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "0.0.1",
"scripts": {
"dev": "vite dev",
"build": "vite build",
"build": "vite build --mode custom",
"preview": "vite preview",
"prepare": "node ../../cli.js sync",
"check": "tsc && svelte-check",
Expand Down
11 changes: 11 additions & 0 deletions packages/kit/test/apps/options/source/app.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/// <reference types="@sveltejs/kit" />

declare namespace App {
interface Locals {}

interface Platform {}

interface Session {}

interface Stuff {}
}
7 changes: 7 additions & 0 deletions packages/kit/test/apps/options/source/pages/mode/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function GET() {
return {
body: {
mode_from_endpoint: import.meta.env.MODE
}
};
}
12 changes: 12 additions & 0 deletions packages/kit/test/apps/options/source/pages/mode/index.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<script>
import { dev, mode as mode_from_import } from '$app/env';

/** @type {string} */
export let mode_from_endpoint;
</script>

<h2>
{mode_from_endpoint} === {mode_from_import} === {import.meta.env.MODE} === {dev
? 'development'
: 'custom'}
</h2>
9 changes: 9 additions & 0 deletions packages/kit/test/apps/options/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,12 @@ test.describe('serviceWorker', () => {
expect(await page.content()).not.toMatch('navigator.serviceWorker');
});
});

test.describe('Vite options', () => {
test('Respects --mode', async ({ page }) => {
await page.goto('/path-base/mode');

const mode = process.env.DEV ? 'development' : 'custom';
expect(await page.textContent('h2')).toBe(`${mode} === ${mode} === ${mode} === ${mode}`);
});
});