|
1 | 1 | import fs from 'fs'; |
2 | 2 | import path from 'path'; |
3 | | -import { svelte } from '@sveltejs/vite-plugin-svelte'; |
4 | 3 | import { mkdirp, posixify } from '../../utils/filesystem.js'; |
5 | 4 | import { deep_merge } from '../../utils/object.js'; |
6 | 5 | import { load_template, print_config_conflicts } from '../config/index.js'; |
7 | | -import { get_aliases, get_runtime_path, resolve_entry } from '../utils.js'; |
8 | | -import { create_build, find_deps } from './utils.js'; |
| 6 | +import { get_runtime_path, resolve_entry } from '../utils.js'; |
| 7 | +import { create_build, find_deps, get_default_config } from './utils.js'; |
9 | 8 | import { s } from '../../utils/misc.js'; |
10 | 9 |
|
11 | 10 | /** |
@@ -107,29 +106,17 @@ export class Server { |
107 | 106 | /** |
108 | 107 | * @param {{ |
109 | 108 | * cwd: string; |
110 | | - * assets_base: string; |
111 | 109 | * config: import('types').ValidatedConfig |
112 | 110 | * manifest_data: import('types').ManifestData |
113 | 111 | * build_dir: string; |
114 | 112 | * output_dir: string; |
115 | 113 | * service_worker_entry_file: string | null; |
116 | | - * service_worker_register: boolean; |
117 | 114 | * }} options |
118 | 115 | * @param {{ vite_manifest: import('vite').Manifest, assets: import('rollup').OutputAsset[] }} client |
119 | 116 | */ |
120 | | -export async function build_server( |
121 | | - { |
122 | | - cwd, |
123 | | - assets_base, |
124 | | - config, |
125 | | - manifest_data, |
126 | | - build_dir, |
127 | | - output_dir, |
128 | | - service_worker_entry_file, |
129 | | - service_worker_register |
130 | | - }, |
131 | | - client |
132 | | -) { |
| 117 | +export async function build_server(options, client) { |
| 118 | + const { cwd, config, manifest_data, build_dir, output_dir, service_worker_entry_file } = options; |
| 119 | + |
133 | 120 | let hooks_file = resolve_entry(config.kit.files.hooks); |
134 | 121 | if (!hooks_file || !fs.existsSync(hooks_file)) { |
135 | 122 | hooks_file = path.join(config.kit.outDir, 'build/hooks.js'); |
@@ -181,7 +168,7 @@ export async function build_server( |
181 | 168 | server_template({ |
182 | 169 | config, |
183 | 170 | hooks: app_relative(hooks_file), |
184 | | - has_service_worker: service_worker_register && !!service_worker_entry_file, |
| 171 | + has_service_worker: config.kit.serviceWorker.register && !!service_worker_entry_file, |
185 | 172 | runtime: get_runtime_path(config), |
186 | 173 | template: load_template(cwd, config) |
187 | 174 | }) |
@@ -211,40 +198,10 @@ export async function build_server( |
211 | 198 | const [modified_vite_config] = deep_merge(default_config, vite_config); |
212 | 199 |
|
213 | 200 | /** @type {[any, string[]]} */ |
214 | | - const [merged_config, conflicts] = deep_merge(modified_vite_config, { |
215 | | - configFile: false, |
216 | | - root: cwd, |
217 | | - base: assets_base, |
218 | | - build: { |
219 | | - ssr: true, |
220 | | - outDir: `${output_dir}/server`, |
221 | | - manifest: true, |
222 | | - polyfillDynamicImport: false, |
223 | | - rollupOptions: { |
224 | | - input, |
225 | | - output: { |
226 | | - format: 'esm', |
227 | | - entryFileNames: '[name].js', |
228 | | - chunkFileNames: 'chunks/[name]-[hash].js', |
229 | | - assetFileNames: 'assets/[name]-[hash][extname]' |
230 | | - }, |
231 | | - preserveEntrySignatures: 'strict' |
232 | | - } |
233 | | - }, |
234 | | - plugins: [ |
235 | | - svelte({ |
236 | | - ...config, |
237 | | - compilerOptions: { |
238 | | - ...config.compilerOptions, |
239 | | - hydratable: !!config.kit.browser.hydrate |
240 | | - }, |
241 | | - configFile: false |
242 | | - }) |
243 | | - ], |
244 | | - resolve: { |
245 | | - alias: get_aliases(config) |
246 | | - } |
247 | | - }); |
| 201 | + const [merged_config, conflicts] = deep_merge( |
| 202 | + modified_vite_config, |
| 203 | + get_default_config({ ...options, input, ssr: true }) |
| 204 | + ); |
248 | 205 |
|
249 | 206 | print_config_conflicts(conflicts, 'kit.vite.', 'build_server'); |
250 | 207 |
|
|
0 commit comments