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

Convert build to Vite plugin and expose as @sveltejs/kit/experimental/vite #5094

Merged
merged 68 commits into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
f177de1
Expose Vite plugin as @sveltejs/kit/vite
benmccann May 27, 2022
97350c5
make svelte config optional
benmccann May 27, 2022
29e118a
Implement build
benmccann May 30, 2022
ea46938
export as experimental/vite for now
benmccann May 31, 2022
e3cd4f5
add plugin correct number of times with or without vite.config.js
benmccann May 31, 2022
225e1c3
add TODO
benmccann Jun 1, 2022
559a413
don't rename dev file for now
benmccann Jun 1, 2022
8fb89d4
update API
benmccann Jun 1, 2022
d59946b
cleanup
benmccann Jun 1, 2022
4d60028
Update packages/kit/src/vite/plugin.js
benmccann Jun 1, 2022
d858c53
Revert "Update packages/kit/src/vite/plugin.js"
benmccann Jun 1, 2022
ad7e9f4
enable validation plugin
benmccann Jun 2, 2022
db7cdb4
enable validation for real this time
benmccann Jun 3, 2022
9092e9f
add validation plugin to all builds
benmccann Jun 3, 2022
168be56
format
benmccann Jun 3, 2022
1ef709d
fix plugin handling
benmccann Jun 3, 2022
fbee989
format
benmccann Jun 3, 2022
cf08947
merge master
benmccann Jun 3, 2022
3347c97
merge master
benmccann Jun 7, 2022
d7ab612
cleanup API
benmccann Jun 7, 2022
8d04589
merge master
benmccann Jun 7, 2022
1e1cf51
remove configFile: false
benmccann Jun 8, 2022
2396a1e
fix validation plugin
benmccann Jun 8, 2022
1a5e933
fix preview
benmccann Jun 8, 2022
554517f
Update healthy-carrots-cross.md
Rich-Harris Jun 22, 2022
5912f29
move dev/build/preview inside vite plugin
Rich-Harris Jun 23, 2022
2fbff0f
move adapt inside build
Rich-Harris Jun 23, 2022
c7de1cb
move all vite-related code into src/vite
Rich-Harris Jun 23, 2022
0b0bfd0
move some more stuff around
Rich-Harris Jun 23, 2022
ab54c88
fix some stuff
Rich-Harris Jun 23, 2022
9b549f0
simplify stuff
Rich-Harris Jun 23, 2022
e5432d1
remove unused plugins_internal
Rich-Harris Jun 23, 2022
db3036e
we can now simplify stuff a bunch
Rich-Harris Jun 23, 2022
e89200a
merge master -> vite
Rich-Harris Jun 23, 2022
a021fc4
simplify
Rich-Harris Jun 23, 2022
e4457d5
lint
benmccann Jun 23, 2022
a8a4693
update path in .prettierrc
benmccann Jun 23, 2022
f66dd1c
revert accidental change
benmccann Jun 23, 2022
95483ee
Merge branch 'master' into vite
benmccann Jun 23, 2022
d4e01e6
try fixing CI
benmccann Jun 23, 2022
6788927
try fixing CI
benmccann Jun 23, 2022
f56618a
lint
Rich-Harris Jun 23, 2022
6f6e3f3
lint
Rich-Harris Jun 23, 2022
1adcd02
fix
Rich-Harris Jun 23, 2022
f6217cd
appease typescript. not sure why this started happening
Rich-Harris Jun 23, 2022
cf4c5c9
whyyy
Rich-Harris Jun 23, 2022
baf6893
simplify
Rich-Harris Jun 23, 2022
d853337
simplify
Rich-Harris Jun 23, 2022
901dd78
simplify
Rich-Harris Jun 23, 2022
250e4b9
respect user config in build
Rich-Harris Jun 23, 2022
7610ab5
update turbo cache
benmccann Jun 23, 2022
75b3f5a
format
benmccann Jun 23, 2022
d655363
resolveJsonModule
benmccann Jun 23, 2022
e2d423f
Merge branch 'vite' of github.com:sveltejs/kit into vite
Rich-Harris Jun 23, 2022
61905b4
remove unnecessary configResolved hook
Rich-Harris Jun 23, 2022
2fd09a9
remove unused option
Rich-Harris Jun 23, 2022
95ddabe
minor simplification
Rich-Harris Jun 23, 2022
8b431a8
simplify
Rich-Harris Jun 23, 2022
288a2fe
move some stuff closer to where its used
Rich-Harris Jun 23, 2022
54f81ee
dry some stuff out, move some stuff to buildStart
Rich-Harris Jun 23, 2022
c8b1f9a
do all config checking up-front
Rich-Harris Jun 23, 2022
f81a86c
remove unused print_config_conflicts
Rich-Harris Jun 23, 2022
4397c02
remove unused import
Rich-Harris Jun 23, 2022
35be9e4
simplify merging
Rich-Harris Jun 23, 2022
da99b0b
remove unused import
Rich-Harris Jun 23, 2022
a63c8bd
remove blank line
benmccann Jun 23, 2022
5ba670e
i think these files were committed by mistake
Rich-Harris Jun 23, 2022
4638cb2
set env vars earlier
Rich-Harris Jun 23, 2022
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
5 changes: 5 additions & 0 deletions .changeset/healthy-carrots-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Expose Vite plugin as @sveltejs/kit/experimental/vite
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"packages/kit/src/packaging/test/fixtures/**/expected/**/*",
"packages/kit/src/packaging/test/watch/expected/**/*",
"packages/kit/src/packaging/test/watch/package/**/*",
"packages/kit/src/core/build/prerender/fixtures/**/*"
"packages/kit/src/vite/build/prerender/fixtures/**/*"
],
"options": {
"requirePragma": true
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/docs
/test/**/.svelte-kit
/test/**/build
!/src/core/adapt/fixtures/*/.svelte-kit
!/src/vite/build/adapt/fixtures/*/.svelte-kit
!/test/node_modules
/test/apps/basics/test/errors.json
.custom-out-dir
3 changes: 3 additions & 0 deletions packages/kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@
},
"./hooks": {
"import": "./dist/hooks.js"
},
"./experimental/vite": {
"import": "./dist/vite.js"
}
},
"types": "types/index.d.ts",
Expand Down
3 changes: 2 additions & 1 deletion packages/kit/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ export default [
cli: 'src/cli.js',
node: 'src/node/index.js',
'node/polyfills': 'src/node/polyfills.js',
hooks: 'src/hooks.js'
hooks: 'src/hooks.js',
vite: 'src/vite/index.js'
},
output: {
dir: 'dist',
Expand Down
92 changes: 38 additions & 54 deletions packages/kit/src/cli.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import chokidar from 'chokidar';
import fs from 'fs';
import path from 'path';
import colors from 'kleur';
import { relative } from 'path';
import sade from 'sade';
import * as vite from 'vite';
import { load_config } from './core/config/index.js';
import { networkInterfaces, release } from 'os';
import { coalesce_to_error } from './utils/error.js';
import { logger } from './core/utils.js';

/** @param {unknown} e */
function handle_error(e) {
Expand Down Expand Up @@ -62,15 +61,8 @@ prog
let close;

async function start() {
const { plugins } = await import('./core/dev/plugin.js');
const svelte_config = await load_config();
const vite_config = await svelte_config.kit.vite();

/** @type {import('vite').UserConfig} */
const config = {
...vite_config,
plugins: [...(vite_config.plugins || []), plugins(svelte_config)]
};
const config = await get_vite_config(svelte_config);
config.server = config.server || {};

// optional config from command-line flags
Expand All @@ -81,7 +73,7 @@ prog

// if https is already enabled then do nothing. it could be an object and we
// don't want to overwrite with a boolean
if (https && !vite_config?.server?.https) {
if (https && !config?.server?.https) {
config.server.https = https;
}

Expand Down Expand Up @@ -158,31 +150,11 @@ prog
.action(async ({ verbose }) => {
try {
process.env.NODE_ENV = process.env.NODE_ENV || 'production';
const config = await load_config();

const log = logger({ verbose });

const { build } = await import('./core/build/index.js');
const { build_data, prerendered } = await build(config, { log });

console.log(
`\nRun ${colors.bold().cyan('npm run preview')} to preview your production build locally.`
);

if (config.kit.adapter) {
const { adapt } = await import('./core/adapt/index.js');
await adapt(config, build_data, prerendered, { log });
process.env.VERBOSE = verbose;

// this is necessary to close any open db connections, etc
process.exit(0);
}

console.log(colors.bold().yellow('\nNo adapter specified'));

// prettier-ignore
console.log(
`See ${colors.bold().cyan('https://kit.svelte.dev/docs/adapters')} to learn how to configure your app to run on the platform of your choosing`
);
const svelte_config = await load_config();
const vite_config = await get_vite_config(svelte_config);
await vite.build(vite_config); // TODO when we get rid of config.kit.vite, this can just be vite.build()
} catch (error) {
handle_error(error);
}
Expand All @@ -202,30 +174,18 @@ prog

process.env.NODE_ENV = process.env.NODE_ENV || 'production';

const { sveltekit_plugin } = await import('./core/preview/index.js');
const svelte_config = await load_config();
const vite_config = await svelte_config.kit.vite();
const vite_config = await get_vite_config(svelte_config);

/** @type {import('vite').UserConfig} */
const config = {
...vite_config,
plugins: [...(vite_config.plugins || []), sveltekit_plugin]
};
config.preview = config.preview || {};
vite_config.preview = vite_config.preview || {};

// optional config from command-line flags
// these should take precedence, but not print conflict warnings
if (host) {
config.preview.host = host;
}
if (https) {
config.preview.https = https;
}
if (port) {
config.preview.port = port;
}
if (host) vite_config.preview.host = host;
if (https) vite_config.preview.https = https;
if (port) vite_config.preview.port = port;

const preview_server = await vite.preview(config);
const preview_server = await vite.preview(vite_config);

welcome({ port, host, https, open, base: preview_server.config.base });
} catch (error) {
Expand Down Expand Up @@ -305,7 +265,7 @@ function welcome({ port, host, https, open, base, loose, allow, cwd }) {
if (loose) {
console.log(`\n ${colors.yellow('Serving with vite.server.fs.strict: false. Note that all files on your machine will be accessible to anyone on your network.')}`);
} else if (allow?.length && cwd) {
console.log(`\n ${colors.yellow('Note that all files in the following directories will be accessible to anyone on your network: ' + allow.map(a => relative(cwd, a)).join(', '))}`);
console.log(`\n ${colors.yellow('Note that all files in the following directories will be accessible to anyone on your network: ' + allow.map(a => path.relative(cwd, a)).join(', '))}`);
}
} else {
console.log(` ${colors.gray('network: not exposed')}`);
Expand All @@ -320,3 +280,27 @@ function welcome({ port, host, https, open, base, loose, allow, cwd }) {

console.log('\n');
}

/**
* @param {import('types').ValidatedConfig} svelte_config
* @return {Promise<import('vite').UserConfig>}
*/
export async function get_vite_config(svelte_config) {
for (const file of ['vite.config.js', 'vite.config.mjs', 'vite.config.cjs']) {
if (fs.existsSync(file)) {
// TODO warn here if config.kit.vite was specified
const module = await import(path.resolve(file));
return {
...module.default,
configFile: false
};
}
}

const { sveltekit } = await import('./vite/index.js');

// TODO: stop reading Vite config from SvelteKit config or move to CLI
const vite_config = await svelte_config.kit.vite();
vite_config.plugins = [...(vite_config.plugins || []), ...sveltekit()];
return vite_config;
}
79 changes: 0 additions & 79 deletions packages/kit/src/core/build/build_client.js

This file was deleted.

91 changes: 0 additions & 91 deletions packages/kit/src/core/build/index.js

This file was deleted.

Loading