Skip to content

Commit

Permalink
Upgrade to Vite 3
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed May 23, 2022
1 parent eb2ab91 commit 5620424
Show file tree
Hide file tree
Showing 12 changed files with 129 additions and 132 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"prettier": "^2.5.0",
"prettier-plugin-svelte": "^2.5.0",
"rimraf": "^3.0.2",
"rollup": "^2.60.2",
"rollup": "^2.74.1",
"sirv": "^2.0.0",
"svelte": "^3.48.0",
"svelte-check": "^2.5.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-cloudflare-workers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"dependencies": {
"@iarna/toml": "^2.2.5",
"esbuild": "^0.14.29"
"esbuild": "^0.14.39"
},
"devDependencies": {
"@cloudflare/kv-asset-handler": "^0.2.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-cloudflare/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"prepublishOnly": "npm run build"
},
"dependencies": {
"esbuild": "^0.14.29",
"esbuild": "^0.14.39",
"worktop": "0.8.0-next.14"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-netlify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
"dependencies": {
"@iarna/toml": "^2.2.5",
"esbuild": "^0.14.29",
"esbuild": "^0.14.39",
"tiny-glob": "^0.2.9"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-vercel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"check": "tsc"
},
"dependencies": {
"esbuild": "^0.14.29"
"esbuild": "^0.14.39"
},
"devDependencies": {
"@sveltejs/kit": "workspace:*"
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@sveltejs/vite-plugin-svelte": "^1.0.0-next.44",
"chokidar": "^3.5.3",
"sade": "^1.7.4",
"vite": "^2.9.9"
"vite": "^3.0.0-alpha.2"
},
"devDependencies": {
"@types/connect": "^3.4.35",
Expand Down
14 changes: 7 additions & 7 deletions packages/kit/src/core/build/build_service_worker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'fs';
import vite from 'vite';
import { build } from 'vite';
import { s } from '../../utils/misc.js';
import { deep_merge } from '../../utils/object.js';
import { normalize_path } from '../../utils/url.js';
Expand All @@ -22,12 +22,12 @@ export async function build_service_worker(
prerendered,
client_manifest
) {
const build = new Set();
const build_files = new Set();
for (const key in client_manifest) {
const { file, css = [], assets = [] } = client_manifest[key];
build.add(file);
css.forEach((file) => build.add(file));
assets.forEach((file) => build.add(file));
build_files.add(file);
css.forEach((file) => build_files.add(file));
assets.forEach((file) => build_files.add(file));
}

const service_worker = `${config.kit.outDir}/generated/service-worker.js`;
Expand All @@ -43,7 +43,7 @@ export async function build_service_worker(
};
export const build = [
${Array.from(build)
${Array.from(build_files)
.map((file) => `${s(`${config.kit.paths.base}/${config.kit.appDir}/${file}`)}`)
.join(',\n\t\t\t\t')}
];
Expand Down Expand Up @@ -96,5 +96,5 @@ export async function build_service_worker(

print_config_conflicts(conflicts, 'kit.vite.', 'build_service_worker');

await vite.build(merged_config);
await build(merged_config);
}
4 changes: 2 additions & 2 deletions packages/kit/src/core/build/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import vite from 'vite';
import { build } from 'vite';

/**
* @typedef {import('rollup').RollupOutput} RollupOutput
Expand All @@ -8,7 +8,7 @@ import vite from 'vite';

/** @param {import('vite').UserConfig} config */
export async function create_build(config) {
const { output } = /** @type {RollupOutput} */ (await vite.build(config));
const { output } = /** @type {RollupOutput} */ (await build(config));

const chunks = output.filter(
/** @returns {output is OutputChunk} */ (output) => output.type === 'chunk'
Expand Down
17 changes: 9 additions & 8 deletions packages/kit/src/core/dev/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'path';
import { svelte } from '@sveltejs/vite-plugin-svelte';
import vite from 'vite';
import { createServer, searchForWorkspaceRoot } from 'vite';
import { deep_merge } from '../../utils/object.js';
import { print_config_conflicts } from '../config/index.js';
import { get_aliases, get_runtime_path } from '../utils.js';
Expand Down Expand Up @@ -33,7 +33,7 @@ export async function dev({ cwd, port, host, https, config }) {
config.kit.outDir,
path.resolve(cwd, 'src'),
path.resolve(cwd, 'node_modules'),
path.resolve(vite.searchForWorkspaceRoot(cwd), 'node_modules')
path.resolve(searchForWorkspaceRoot(cwd), 'node_modules')
])
]
},
Expand All @@ -49,11 +49,8 @@ export async function dev({ cwd, port, host, https, config }) {

/** @type {[any, string[]]} */
const [merged_config, conflicts] = deep_merge(vite_config, {
base: '/',
configFile: false,
root: cwd,
resolve: {
alias: get_aliases(config)
},
build: {
rollupOptions: {
// Vite dependency crawler needs an explicit JS entry point
Expand All @@ -73,7 +70,11 @@ export async function dev({ cwd, port, host, https, config }) {
}),
await create_plugin(config, cwd)
],
base: '/'
resolve: {
alias: get_aliases(config)
},
root: cwd,
spa: false
});

print_config_conflicts(conflicts, 'kit.vite.');
Expand All @@ -94,7 +95,7 @@ export async function dev({ cwd, port, host, https, config }) {
merged_config.server.port = port;
}

const server = await vite.createServer(merged_config);
const server = await createServer(merged_config);
await server.listen(port);

const address_info = /** @type {import('net').AddressInfo} */ (
Expand Down
3 changes: 0 additions & 3 deletions packages/kit/src/core/dev/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,6 @@ function not_found(res, message = 'Not found') {
*/
function remove_html_middlewares(server) {
const html_middlewares = [
'viteIndexHtmlMiddleware',
'vite404Middleware',
'viteSpaFallbackMiddleware',
'viteServeStaticMiddleware'
];
for (let i = server.stack.length - 1; i > 0; i--) {
Expand Down
Loading

0 comments on commit 5620424

Please sign in to comment.