Skip to content

Commit b65efa2

Browse files
authored
chore: clean up options interface (#109)
1 parent ed2a22d commit b65efa2

File tree

1 file changed

+12
-145
lines changed

1 file changed

+12
-145
lines changed

packages/vite-plugin-svelte/src/utils/options.ts

Lines changed: 12 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { log } from './log';
44
import { loadSvelteConfig } from './load-svelte-config';
55
import { SVELTE_HMR_IMPORTS, SVELTE_IMPORTS, SVELTE_RESOLVE_MAIN_FIELDS } from './constants';
66
// eslint-disable-next-line node/no-missing-import
7-
import { CompileOptions } from 'svelte/types/compiler/interfaces';
7+
import { CompileOptions, Warning } from 'svelte/types/compiler/interfaces';
88
import {
99
MarkupPreprocessor,
1010
Preprocessor,
@@ -23,7 +23,6 @@ const knownOptions = new Set([
2323
'onwarn',
2424
'preprocess',
2525
'hot',
26-
'disableCssHmr',
2726
'ignorePluginPreprocessors',
2827
'experimental'
2928
]);
@@ -261,132 +260,11 @@ export interface Options {
261260
* YOU HAVE BEEN WARNED
262261
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
263262
*
263+
* set to object to pass custom options to svelte-hmr, see https://github.com/rixo/svelte-hmr#options
264+
*
264265
* @default true for development, always false for production
265266
*/
266-
hot?:
267-
| undefined
268-
| boolean
269-
| {
270-
// svelte-hmr options
271-
/**
272-
* preserve all local state
273-
* @default false
274-
*/
275-
preserveLocalState?: boolean;
276-
277-
/**
278-
* escape hatchs from preservation of local state
279-
* disable preservation of state for this component
280-
*
281-
* @default ['\@hmr:reset', '\@!hmr']
282-
*/
283-
noPreserveStateKey?: string[];
284-
285-
/**
286-
* enable preservation of state for all variables in this component
287-
*
288-
* @default '\@hmr:keep-all'
289-
*/
290-
preserveAllLocalStateKey?: string;
291-
292-
/**
293-
* enable preservation of state for a given variable (must be inline or
294-
* above the target variable or variables; can be repeated)
295-
*
296-
* @default '\@hmr:keep'
297-
*/
298-
preserveLocalStateKey?: string;
299-
300-
/**
301-
* don't reload on fatal error
302-
*
303-
* @default false
304-
*/
305-
noReload?: boolean;
306-
307-
/**
308-
* try to recover after runtime errors during component init
309-
*
310-
* @default true
311-
*/
312-
optimistic?: boolean;
313-
/**
314-
* auto accept modules of components that have named exports (i.e. exports
315-
* from context="module")
316-
*
317-
* @default true
318-
*/
319-
acceptNamedExports?: boolean;
320-
321-
/**
322-
* auto accept modules of components have accessors (either accessors compile
323-
* option, or \<svelte:option accessors=\{true\} /\>) -- this means that if you
324-
* set accessors compile option globally, you must also set this option to
325-
* true, or no component will be hot reloaded (but there are a lot of edge
326-
* cases that HMR can't support correctly with accessors)
327-
*
328-
* @default true
329-
*/
330-
acceptAccessors?: boolean;
331-
332-
/**
333-
* only inject CSS instead of recreating components when only CSS changes
334-
*
335-
* @default true, but vite-plugin-svelte configures this automatically according to emitCss requirements
336-
*/
337-
injectCss?: boolean;
338-
339-
/**
340-
* to mitigate FOUC between dispose (remove stylesheet) and accept
341-
*
342-
* note: has no effect when emitCss is true (vite-plugin-svelte default)
343-
* @default 100
344-
*/
345-
cssEjectDelay?: number;
346-
347-
//
348-
/**
349-
* Svelte Native mode
350-
*
351-
* @default false
352-
*/
353-
native?: boolean;
354-
355-
/**
356-
* name of the adapter import binding
357-
*
358-
* @default '___SVELTE_HMR_HOT_API_PROXY_ADAPTER'
359-
*/
360-
importAdapterName?: string;
361-
/**
362-
* use absolute file paths to import runtime deps of svelte-hmr
363-
* (see https://github.com/rixo/svelte-hmr/issues/11)
364-
*
365-
* @default true
366-
*/
367-
absoluteImports?: boolean;
368-
369-
/**
370-
* disable runtime error overlay
371-
*
372-
* @default false
373-
*/
374-
noOverlay?: boolean;
375-
376-
/**
377-
* custom import path for hotApi
378-
*/
379-
hotApi?: string;
380-
/**
381-
* custom path for adapter
382-
*/
383-
adapter?: string;
384-
};
385-
/**
386-
* disable separate hmr update for css files via vite
387-
* @default false
388-
*/
389-
disableCssHmr?: boolean;
267+
hot?: boolean | { injectCss?: boolean; [key: string]: any };
390268

391269
/**
392270
* vite plugins can contribute additional preprocessors by defining api.sveltePreprocess.
@@ -429,28 +307,17 @@ export interface ResolvedOptions extends Options {
429307
server?: ViteDevServer;
430308
}
431309

432-
export type { CompileOptions, Processed, MarkupPreprocessor, Preprocessor, PreprocessorGroup };
310+
export type {
311+
CompileOptions,
312+
Processed,
313+
MarkupPreprocessor,
314+
Preprocessor,
315+
PreprocessorGroup,
316+
Warning
317+
};
433318

434319
export type ModuleFormat = NonNullable<CompileOptions['format']>;
435320

436321
export type CssHashGetter = NonNullable<CompileOptions['cssHash']>;
437322

438323
export type Arrayable<T> = T | T[];
439-
440-
export interface Warning {
441-
start?: {
442-
line: number;
443-
column: number;
444-
pos?: number;
445-
};
446-
end?: {
447-
line: number;
448-
column: number;
449-
};
450-
pos?: number;
451-
code: string;
452-
message: string;
453-
filename?: string;
454-
frame?: string;
455-
toString: () => string;
456-
}

0 commit comments

Comments
 (0)