@sveltejs/vite-plugin-svelte 3.0.0-next.1 → 3.0.0-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +16 -12
- package/src/index.js +4 -1
- package/src/preprocess.js +8 -5
- package/src/{index.d.ts → public.d.ts} +34 -65
- package/src/types/compile.d.ts +2 -25
- package/src/types/log.d.ts +1 -1
- package/src/types/options.d.ts +1 -1
- package/src/utils/compile.js +1 -1
- package/src/utils/error.js +1 -1
- package/src/utils/esbuild.js +1 -1
- package/src/utils/id.js +2 -2
- package/src/utils/load-svelte-config.js +13 -10
- package/src/utils/options.js +6 -6
- package/src/utils/preprocess.js +5 -5
- package/types/index.d.ts +189 -0
- package/types/index.d.ts.map +25 -0
package/package.json
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltejs/vite-plugin-svelte",
|
|
3
|
-
"version": "3.0.0-next.
|
|
3
|
+
"version": "3.0.0-next.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "dominikg",
|
|
6
6
|
"files": [
|
|
7
|
-
"src"
|
|
7
|
+
"src",
|
|
8
|
+
"types"
|
|
8
9
|
],
|
|
9
10
|
"type": "module",
|
|
10
|
-
"types": "
|
|
11
|
+
"types": "types/index.d.ts",
|
|
11
12
|
"exports": {
|
|
12
13
|
".": {
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
"import": {
|
|
15
|
+
"types": "./types/index.d.ts",
|
|
16
|
+
"default": "./src/index.js"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
17
19
|
},
|
|
18
20
|
"engines": {
|
|
19
21
|
"node": "^18.0.0 || >=20"
|
|
@@ -47,13 +49,15 @@
|
|
|
47
49
|
"vite": "^5.0.0-beta.1 || ^5.0.0"
|
|
48
50
|
},
|
|
49
51
|
"devDependencies": {
|
|
50
|
-
"@types/debug": "^4.1.
|
|
51
|
-
"esbuild": "^0.19.
|
|
52
|
-
"
|
|
53
|
-
"
|
|
52
|
+
"@types/debug": "^4.1.10",
|
|
53
|
+
"esbuild": "^0.19.5",
|
|
54
|
+
"sass": "^1.69.5",
|
|
55
|
+
"svelte": "^4.2.2",
|
|
56
|
+
"vite": "^5.0.0-beta.12"
|
|
54
57
|
},
|
|
55
58
|
"scripts": {
|
|
56
59
|
"check:publint": "publint --strict",
|
|
57
|
-
"check:types": "tsc --noEmit"
|
|
60
|
+
"check:types": "tsc --noEmit",
|
|
61
|
+
"generate:types": "dts-buddy -m \"@sveltejs/vite-plugin-svelte:src/public.d.ts\""
|
|
58
62
|
}
|
|
59
63
|
}
|
package/src/index.js
CHANGED
|
@@ -20,7 +20,10 @@ import { saveSvelteMetadata } from './utils/optimizer.js';
|
|
|
20
20
|
import { VitePluginSvelteCache } from './utils/vite-plugin-svelte-cache.js';
|
|
21
21
|
import { loadRaw } from './utils/load-raw.js';
|
|
22
22
|
|
|
23
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* @param {Partial<import('./public.d.ts').Options>} [inlineOptions]
|
|
25
|
+
* @returns {import('vite').Plugin[]}
|
|
26
|
+
*/
|
|
24
27
|
export function svelte(inlineOptions) {
|
|
25
28
|
if (process.env.DEBUG != null) {
|
|
26
29
|
log.setLevel('debug');
|
package/src/preprocess.js
CHANGED
|
@@ -9,9 +9,12 @@ const supportedScriptLangs = ['ts'];
|
|
|
9
9
|
|
|
10
10
|
export const lang_sep = '.vite-preprocess';
|
|
11
11
|
|
|
12
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* @param {import('./public.d.ts').VitePreprocessOptions} opts
|
|
14
|
+
* @returns {import('svelte/compiler').PreprocessorGroup}
|
|
15
|
+
*/
|
|
13
16
|
export function vitePreprocess(opts) {
|
|
14
|
-
/** @type {import('svelte/
|
|
17
|
+
/** @type {import('svelte/compiler').PreprocessorGroup} */
|
|
15
18
|
const preprocessor = { name: 'vite-preprocess' };
|
|
16
19
|
if (opts?.script !== false) {
|
|
17
20
|
preprocessor.script = viteScript().script;
|
|
@@ -24,7 +27,7 @@ export function vitePreprocess(opts) {
|
|
|
24
27
|
}
|
|
25
28
|
|
|
26
29
|
/**
|
|
27
|
-
* @returns {{ script: import('svelte/
|
|
30
|
+
* @returns {{ script: import('svelte/compiler').Preprocessor }}
|
|
28
31
|
*/
|
|
29
32
|
function viteScript() {
|
|
30
33
|
return {
|
|
@@ -55,12 +58,12 @@ function viteScript() {
|
|
|
55
58
|
|
|
56
59
|
/**
|
|
57
60
|
* @param {import('vite').ResolvedConfig | import('vite').InlineConfig} config
|
|
58
|
-
* @returns {{ style: import('svelte/
|
|
61
|
+
* @returns {{ style: import('svelte/compiler').Preprocessor }}
|
|
59
62
|
*/
|
|
60
63
|
function viteStyle(config = {}) {
|
|
61
64
|
/** @type {CssTransform} */
|
|
62
65
|
let transform;
|
|
63
|
-
/** @type {import('svelte/
|
|
66
|
+
/** @type {import('svelte/compiler').Preprocessor} */
|
|
64
67
|
const style = async ({ attributes, content, filename = '' }) => {
|
|
65
68
|
const ext = attributes.lang ? `.${attributes.lang}` : '.css';
|
|
66
69
|
if (attributes.lang && !isCSSRequest(ext)) return;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import type { InlineConfig, ResolvedConfig
|
|
2
|
-
import type { CompileOptions
|
|
3
|
-
import type {
|
|
1
|
+
import type { InlineConfig, ResolvedConfig } from 'vite';
|
|
2
|
+
import type { CompileOptions } from 'svelte/compiler';
|
|
3
|
+
import type { Warning } from 'svelte/types/compiler/interfaces';
|
|
4
|
+
import type { PreprocessorGroup } from 'svelte/compiler';
|
|
4
5
|
import type { Options as InspectorOptions } from '@sveltejs/vite-plugin-svelte-inspector';
|
|
5
6
|
|
|
6
|
-
type Options = Omit<
|
|
7
|
+
export type Options = Omit<SvelteConfig, 'vitePlugin'> & PluginOptionsInline;
|
|
7
8
|
|
|
8
9
|
interface PluginOptionsInline extends PluginOptions {
|
|
9
10
|
/**
|
|
@@ -94,13 +95,39 @@ interface PluginOptions {
|
|
|
94
95
|
* @default unset for dev, always false for build
|
|
95
96
|
*/
|
|
96
97
|
inspector?: InspectorOptions | boolean;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* A function to update `compilerOptions` before compilation
|
|
101
|
+
*
|
|
102
|
+
* `data.filename` - The file to be compiled
|
|
103
|
+
* `data.code` - The preprocessed Svelte code
|
|
104
|
+
* `data.compileOptions` - The current compiler options
|
|
105
|
+
*
|
|
106
|
+
* To change part of the compiler options, return an object with the changes you need.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```
|
|
110
|
+
* ({ filename, compileOptions }) => {
|
|
111
|
+
* // Dynamically set hydration per Svelte file
|
|
112
|
+
* if (compileWithHydratable(filename) && !compileOptions.hydratable) {
|
|
113
|
+
* return { hydratable: true };
|
|
114
|
+
* }
|
|
115
|
+
* }
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
dynamicCompileOptions?: (data: {
|
|
119
|
+
filename: string;
|
|
120
|
+
code: string;
|
|
121
|
+
compileOptions: Partial<CompileOptions>;
|
|
122
|
+
}) => Promise<Partial<CompileOptions> | void> | Partial<CompileOptions> | void;
|
|
123
|
+
|
|
97
124
|
/**
|
|
98
125
|
* These options are considered experimental and breaking changes to them can occur in any release
|
|
99
126
|
*/
|
|
100
127
|
experimental?: ExperimentalOptions;
|
|
101
128
|
}
|
|
102
129
|
|
|
103
|
-
interface
|
|
130
|
+
export interface SvelteConfig {
|
|
104
131
|
/**
|
|
105
132
|
* A list of file extensions to be compiled by Svelte
|
|
106
133
|
*
|
|
@@ -122,31 +149,6 @@ interface SvelteOptions {
|
|
|
122
149
|
*/
|
|
123
150
|
compilerOptions?: Omit<CompileOptions, 'filename' | 'format' | 'generate'>;
|
|
124
151
|
|
|
125
|
-
/**
|
|
126
|
-
* A function to update `compilerOptions` before compilation
|
|
127
|
-
*
|
|
128
|
-
* `data.filename` - The file to be compiled
|
|
129
|
-
* `data.code` - The preprocessed Svelte code
|
|
130
|
-
* `data.compileOptions` - The current compiler options
|
|
131
|
-
*
|
|
132
|
-
* To change part of the compiler options, return an object with the changes you need.
|
|
133
|
-
*
|
|
134
|
-
* @example
|
|
135
|
-
* ```
|
|
136
|
-
* ({ filename, compileOptions }) => {
|
|
137
|
-
* // Dynamically set hydration per Svelte file
|
|
138
|
-
* if (compileWithHydratable(filename) && !compileOptions.hydratable) {
|
|
139
|
-
* return { hydratable: true };
|
|
140
|
-
* }
|
|
141
|
-
* }
|
|
142
|
-
* ```
|
|
143
|
-
*/
|
|
144
|
-
dynamicCompileOptions?: (data: {
|
|
145
|
-
filename: string;
|
|
146
|
-
code: string;
|
|
147
|
-
compileOptions: Partial<CompileOptions>;
|
|
148
|
-
}) => Promise<Partial<CompileOptions> | void> | Partial<CompileOptions> | void;
|
|
149
|
-
|
|
150
152
|
/**
|
|
151
153
|
* Handles warning emitted from the Svelte compiler
|
|
152
154
|
*/
|
|
@@ -174,44 +176,11 @@ interface ExperimentalOptions {
|
|
|
174
176
|
disableSvelteResolveWarnings?: boolean;
|
|
175
177
|
}
|
|
176
178
|
|
|
177
|
-
type ModuleFormat = NonNullable<'esm'>;
|
|
178
|
-
type CssHashGetter = NonNullable<CompileOptions['cssHash']>;
|
|
179
179
|
type Arrayable<T> = T | T[];
|
|
180
180
|
|
|
181
|
-
interface VitePreprocessOptions {
|
|
181
|
+
export interface VitePreprocessOptions {
|
|
182
182
|
script?: boolean;
|
|
183
183
|
style?: boolean | InlineConfig | ResolvedConfig;
|
|
184
184
|
}
|
|
185
185
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
declare function loadSvelteConfig(
|
|
189
|
-
viteConfig?: UserConfig,
|
|
190
|
-
inlineOptions?: Partial<Options>
|
|
191
|
-
): Promise<Partial<SvelteOptions> | undefined>;
|
|
192
|
-
|
|
193
|
-
declare function svelte(inlineOptions?: Partial<Options>): Plugin[];
|
|
194
|
-
|
|
195
|
-
export {
|
|
196
|
-
Arrayable,
|
|
197
|
-
CssHashGetter,
|
|
198
|
-
ModuleFormat,
|
|
199
|
-
Options,
|
|
200
|
-
PluginOptions,
|
|
201
|
-
SvelteOptions,
|
|
202
|
-
loadSvelteConfig,
|
|
203
|
-
svelte,
|
|
204
|
-
VitePreprocessOptions,
|
|
205
|
-
vitePreprocess
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
// reexported types
|
|
209
|
-
|
|
210
|
-
export { CompileOptions, Warning } from 'svelte/types/compiler/interfaces';
|
|
211
|
-
|
|
212
|
-
export {
|
|
213
|
-
MarkupPreprocessor,
|
|
214
|
-
Preprocessor,
|
|
215
|
-
PreprocessorGroup,
|
|
216
|
-
Processed
|
|
217
|
-
} from 'svelte/types/compiler/preprocess';
|
|
186
|
+
export * from './index.js';
|
package/src/types/compile.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Processed } from 'svelte/
|
|
1
|
+
import type { Processed, CompileResult } from 'svelte/compiler';
|
|
2
2
|
import type { SvelteRequest } from './id.d.ts';
|
|
3
3
|
import type { ResolvedOptions } from './options.d.ts';
|
|
4
4
|
|
|
@@ -14,34 +14,11 @@ export interface Code {
|
|
|
14
14
|
dependencies?: any[];
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export interface Compiled {
|
|
18
|
-
js: Code;
|
|
19
|
-
css: Code;
|
|
20
|
-
ast: any; // TODO type
|
|
21
|
-
warnings: any[]; // TODO type
|
|
22
|
-
vars: Array<{
|
|
23
|
-
name: string;
|
|
24
|
-
export_name: string;
|
|
25
|
-
injected: boolean;
|
|
26
|
-
module: boolean;
|
|
27
|
-
mutated: boolean;
|
|
28
|
-
reassigned: boolean;
|
|
29
|
-
referenced: boolean;
|
|
30
|
-
writable: boolean;
|
|
31
|
-
referenced_from_script: boolean;
|
|
32
|
-
}>;
|
|
33
|
-
stats: {
|
|
34
|
-
timings: {
|
|
35
|
-
total: number;
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
17
|
export interface CompileData {
|
|
41
18
|
filename: string;
|
|
42
19
|
normalizedFilename: string;
|
|
43
20
|
lang: string;
|
|
44
|
-
compiled:
|
|
21
|
+
compiled: CompileResult;
|
|
45
22
|
ssr: boolean | undefined;
|
|
46
23
|
dependencies: string[];
|
|
47
24
|
preprocessed: Processed;
|
package/src/types/log.d.ts
CHANGED
package/src/types/options.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { CompileOptions } from 'svelte/types/compiler/interfaces';
|
|
2
2
|
import type { ViteDevServer } from 'vite';
|
|
3
3
|
import { VitePluginSvelteStats } from '../utils/vite-plugin-svelte-stats.js';
|
|
4
|
-
import type { Options } from '../
|
|
4
|
+
import type { Options } from '../public.d.ts';
|
|
5
5
|
|
|
6
6
|
export interface PreResolvedOptions extends Options {
|
|
7
7
|
// these options are non-nullable after resolve
|
package/src/utils/compile.js
CHANGED
|
@@ -54,7 +54,7 @@ export const _createCompileSvelte = (makeHot) => {
|
|
|
54
54
|
// also they for hmr updates too
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
|
-
/** @type {import('
|
|
57
|
+
/** @type {import('svelte/compiler').CompileOptions} */
|
|
58
58
|
const compileOptions = {
|
|
59
59
|
...options.compilerOptions,
|
|
60
60
|
filename,
|
package/src/utils/error.js
CHANGED
|
@@ -104,7 +104,7 @@ function formatFrameForVite(frame) {
|
|
|
104
104
|
/**
|
|
105
105
|
* @param {import('svelte/types/compiler/interfaces').Warning & Error} err a svelte compiler error, which is a mix of Warning and an error
|
|
106
106
|
* @param {string} originalCode
|
|
107
|
-
* @param {import('../
|
|
107
|
+
* @param {import('../public.d.ts').Options['preprocess']} [preprocessors]
|
|
108
108
|
*/
|
|
109
109
|
export function enhanceCompileError(err, originalCode, preprocessors) {
|
|
110
110
|
preprocessors = arraify(preprocessors ?? []);
|
package/src/utils/esbuild.js
CHANGED
|
@@ -59,7 +59,7 @@ async function compileSvelte(options, { filename, code }, statsCollection) {
|
|
|
59
59
|
// TODO ideally we'd be able to externalize prebundled styles too, but for now always put them in the js
|
|
60
60
|
css = 'injected';
|
|
61
61
|
}
|
|
62
|
-
/** @type {import('
|
|
62
|
+
/** @type {import('svelte/compiler').CompileOptions} */
|
|
63
63
|
const compileOptions = {
|
|
64
64
|
...options.compilerOptions,
|
|
65
65
|
css,
|
package/src/utils/id.js
CHANGED
|
@@ -159,8 +159,8 @@ function stripRoot(normalizedFilename, normalizedRoot) {
|
|
|
159
159
|
}
|
|
160
160
|
|
|
161
161
|
/**
|
|
162
|
-
* @param {import('../
|
|
163
|
-
* @param {import('../
|
|
162
|
+
* @param {import('../public.d.ts').Options['include'] | undefined} include
|
|
163
|
+
* @param {import('../public.d.ts').Options['exclude'] | undefined} exclude
|
|
164
164
|
* @param {string[]} extensions
|
|
165
165
|
* @returns {(filename: string) => boolean}
|
|
166
166
|
*/
|
|
@@ -16,16 +16,19 @@ export const knownSvelteConfigNames = [
|
|
|
16
16
|
'svelte.config.mjs'
|
|
17
17
|
];
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
'timestamp
|
|
25
|
-
|
|
26
|
-
);
|
|
19
|
+
/**
|
|
20
|
+
* @param {string} filePath
|
|
21
|
+
* @param {number} timestamp
|
|
22
|
+
*/
|
|
23
|
+
async function dynamicImportDefault(filePath, timestamp) {
|
|
24
|
+
return await import(filePath + '?t=' + timestamp).then((m) => m.default);
|
|
25
|
+
}
|
|
27
26
|
|
|
28
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* @param {import('vite').UserConfig} viteConfig
|
|
29
|
+
* @param {Partial<import('../public.d.ts').Options>} inlineOptions
|
|
30
|
+
* @returns {Promise<Partial<import('../public.d.ts').SvelteConfig> | undefined>}
|
|
31
|
+
*/
|
|
29
32
|
export async function loadSvelteConfig(viteConfig, inlineOptions) {
|
|
30
33
|
if (inlineOptions?.configFile === false) {
|
|
31
34
|
return;
|
|
@@ -87,7 +90,7 @@ export async function loadSvelteConfig(viteConfig, inlineOptions) {
|
|
|
87
90
|
|
|
88
91
|
/**
|
|
89
92
|
* @param {import('vite').UserConfig | undefined} viteConfig
|
|
90
|
-
* @param {Partial<import('../
|
|
93
|
+
* @param {Partial<import('../public.d.ts').Options> | undefined} inlineOptions
|
|
91
94
|
* @returns {string | undefined}
|
|
92
95
|
*/
|
|
93
96
|
function findConfigToLoad(viteConfig, inlineOptions) {
|
package/src/utils/options.js
CHANGED
|
@@ -45,7 +45,7 @@ const knownRootOptions = new Set(['extensions', 'compilerOptions', 'preprocess',
|
|
|
45
45
|
const allowedInlineOptions = new Set(['configFile', ...allowedPluginOptions, ...knownRootOptions]);
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
|
-
* @param {Partial<import('../
|
|
48
|
+
* @param {Partial<import('../public.d.ts').Options>} [inlineOptions]
|
|
49
49
|
*/
|
|
50
50
|
export function validateInlineOptions(inlineOptions) {
|
|
51
51
|
const invalidKeys = Object.keys(inlineOptions || {}).filter(
|
|
@@ -57,8 +57,8 @@ export function validateInlineOptions(inlineOptions) {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
/**
|
|
60
|
-
* @param {Partial<import('../
|
|
61
|
-
* @returns {Partial<import('../
|
|
60
|
+
* @param {Partial<import('../public.d.ts').SvelteConfig>} [config]
|
|
61
|
+
* @returns {Partial<import('../public.d.ts').Options> | undefined}
|
|
62
62
|
*/
|
|
63
63
|
function convertPluginOptions(config) {
|
|
64
64
|
if (!config) {
|
|
@@ -108,7 +108,7 @@ function convertPluginOptions(config) {
|
|
|
108
108
|
delete pluginOptions[unkownOption];
|
|
109
109
|
});
|
|
110
110
|
}
|
|
111
|
-
/** @type {import('../
|
|
111
|
+
/** @type {import('../public.d.ts').Options} */
|
|
112
112
|
const result = {
|
|
113
113
|
...config,
|
|
114
114
|
...pluginOptions
|
|
@@ -121,7 +121,7 @@ function convertPluginOptions(config) {
|
|
|
121
121
|
|
|
122
122
|
/**
|
|
123
123
|
* used in config phase, merges the default options, svelte config, and inline options
|
|
124
|
-
* @param {Partial<import('../
|
|
124
|
+
* @param {Partial<import('../public.d.ts').Options> | undefined} inlineOptions
|
|
125
125
|
* @param {import('vite').UserConfig} viteUserConfig
|
|
126
126
|
* @param {import('vite').ConfigEnv} viteEnv
|
|
127
127
|
* @returns {Promise<import('../types/options.d.ts').PreResolvedOptions>}
|
|
@@ -191,7 +191,7 @@ function mergeConfigs(...configs) {
|
|
|
191
191
|
*/
|
|
192
192
|
export function resolveOptions(preResolveOptions, viteConfig, cache) {
|
|
193
193
|
const css = preResolveOptions.emitCss ? 'external' : 'injected';
|
|
194
|
-
/** @type {Partial<import('../
|
|
194
|
+
/** @type {Partial<import('../public.d.ts').Options>} */
|
|
195
195
|
const defaultOptions = {
|
|
196
196
|
hot: viteConfig.isProduction
|
|
197
197
|
? false
|
package/src/utils/preprocess.js
CHANGED
|
@@ -9,7 +9,7 @@ import { normalizePath } from 'vite';
|
|
|
9
9
|
*
|
|
10
10
|
* only used during dev with enabled css hmr
|
|
11
11
|
*
|
|
12
|
-
* @returns {import('svelte/
|
|
12
|
+
* @returns {import('svelte/compiler').PreprocessorGroup}
|
|
13
13
|
*/
|
|
14
14
|
export function createInjectScopeEverythingRulePreprocessorGroup() {
|
|
15
15
|
return {
|
|
@@ -32,14 +32,14 @@ export function createInjectScopeEverythingRulePreprocessorGroup() {
|
|
|
32
32
|
* @param {import('../types/options.d.ts').ResolvedOptions} options
|
|
33
33
|
* @param {import('vite').ResolvedConfig} config
|
|
34
34
|
* @returns {{
|
|
35
|
-
* prependPreprocessors: import('svelte/
|
|
36
|
-
* appendPreprocessors: import('svelte/
|
|
35
|
+
* prependPreprocessors: import('svelte/compiler').PreprocessorGroup[],
|
|
36
|
+
* appendPreprocessors: import('svelte/compiler').PreprocessorGroup[]
|
|
37
37
|
* }}
|
|
38
38
|
*/
|
|
39
39
|
function buildExtraPreprocessors(options, config) {
|
|
40
|
-
/** @type {import('svelte/
|
|
40
|
+
/** @type {import('svelte/compiler').PreprocessorGroup[]} */
|
|
41
41
|
const prependPreprocessors = [];
|
|
42
|
-
/** @type {import('svelte/
|
|
42
|
+
/** @type {import('svelte/compiler').PreprocessorGroup[]} */
|
|
43
43
|
const appendPreprocessors = [];
|
|
44
44
|
|
|
45
45
|
// @ts-ignore
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
declare module '@sveltejs/vite-plugin-svelte' {
|
|
2
|
+
import type { InlineConfig, ResolvedConfig } from 'vite';
|
|
3
|
+
import type { CompileOptions, PreprocessorGroup } from 'svelte/compiler';
|
|
4
|
+
import type { Warning } from 'svelte/types/compiler/interfaces';
|
|
5
|
+
import type { Options as InspectorOptions } from '@sveltejs/vite-plugin-svelte-inspector';
|
|
6
|
+
export type Options = Omit<SvelteConfig, 'vitePlugin'> & PluginOptionsInline;
|
|
7
|
+
|
|
8
|
+
interface PluginOptionsInline extends PluginOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Path to a svelte config file, either absolute or relative to Vite root
|
|
11
|
+
*
|
|
12
|
+
* set to `false` to ignore the svelte config file
|
|
13
|
+
*
|
|
14
|
+
* @see https://vitejs.dev/config/#root
|
|
15
|
+
*/
|
|
16
|
+
configFile?: string | false;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface PluginOptions {
|
|
20
|
+
/**
|
|
21
|
+
* A `picomatch` pattern, or array of patterns, which specifies the files the plugin should
|
|
22
|
+
* operate on. By default, all svelte files are included.
|
|
23
|
+
*
|
|
24
|
+
* @see https://github.com/micromatch/picomatch
|
|
25
|
+
*/
|
|
26
|
+
include?: Arrayable<string>;
|
|
27
|
+
/**
|
|
28
|
+
* A `picomatch` pattern, or array of patterns, which specifies the files to be ignored by the
|
|
29
|
+
* plugin. By default, no files are ignored.
|
|
30
|
+
*
|
|
31
|
+
* @see https://github.com/micromatch/picomatch
|
|
32
|
+
*/
|
|
33
|
+
exclude?: Arrayable<string>;
|
|
34
|
+
/**
|
|
35
|
+
* Emit Svelte styles as virtual CSS files for Vite and other plugins to process
|
|
36
|
+
*
|
|
37
|
+
* @default true
|
|
38
|
+
*/
|
|
39
|
+
emitCss?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Enable or disable Hot Module Replacement.
|
|
42
|
+
*
|
|
43
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
44
|
+
*
|
|
45
|
+
* DO NOT CUSTOMIZE SVELTE-HMR OPTIONS UNLESS YOU KNOW EXACTLY WHAT YOU ARE DOING
|
|
46
|
+
*
|
|
47
|
+
* YOU HAVE BEEN WARNED
|
|
48
|
+
*
|
|
49
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
50
|
+
*
|
|
51
|
+
* Set an object to pass custom options to svelte-hmr
|
|
52
|
+
*
|
|
53
|
+
* @see https://github.com/rixo/svelte-hmr#options
|
|
54
|
+
* @default true for development, always false for production
|
|
55
|
+
*/
|
|
56
|
+
hot?:
|
|
57
|
+
| boolean
|
|
58
|
+
| {
|
|
59
|
+
injectCss?: boolean;
|
|
60
|
+
partialAccept?: boolean;
|
|
61
|
+
[key: string]: any;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Some Vite plugins can contribute additional preprocessors by defining `api.sveltePreprocess`.
|
|
65
|
+
* If you don't want to use them, set this to true to ignore them all or use an array of strings
|
|
66
|
+
* with plugin names to specify which.
|
|
67
|
+
*
|
|
68
|
+
* @default false
|
|
69
|
+
*/
|
|
70
|
+
ignorePluginPreprocessors?: boolean | string[];
|
|
71
|
+
/**
|
|
72
|
+
* vite-plugin-svelte automatically handles excluding svelte libraries and reinclusion of their dependencies
|
|
73
|
+
* in vite.optimizeDeps.
|
|
74
|
+
*
|
|
75
|
+
* `disableDependencyReinclusion: true` disables all reinclusions
|
|
76
|
+
* `disableDependencyReinclusion: ['foo','bar']` disables reinclusions for dependencies of foo and bar
|
|
77
|
+
*
|
|
78
|
+
* This should be used for hybrid packages that contain both node and browser dependencies, eg Routify
|
|
79
|
+
*
|
|
80
|
+
* @default false
|
|
81
|
+
*/
|
|
82
|
+
disableDependencyReinclusion?: boolean | string[];
|
|
83
|
+
/**
|
|
84
|
+
* Enable support for Vite's dependency optimization to prebundle Svelte libraries.
|
|
85
|
+
*
|
|
86
|
+
* To disable prebundling for a specific library, add it to `optimizeDeps.exclude`.
|
|
87
|
+
*
|
|
88
|
+
* @default true for dev, false for build
|
|
89
|
+
*/
|
|
90
|
+
prebundleSvelteLibraries?: boolean;
|
|
91
|
+
/**
|
|
92
|
+
* toggle/configure Svelte Inspector
|
|
93
|
+
*
|
|
94
|
+
* @default unset for dev, always false for build
|
|
95
|
+
*/
|
|
96
|
+
inspector?: InspectorOptions | boolean;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* A function to update `compilerOptions` before compilation
|
|
100
|
+
*
|
|
101
|
+
* `data.filename` - The file to be compiled
|
|
102
|
+
* `data.code` - The preprocessed Svelte code
|
|
103
|
+
* `data.compileOptions` - The current compiler options
|
|
104
|
+
*
|
|
105
|
+
* To change part of the compiler options, return an object with the changes you need.
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```
|
|
109
|
+
* ({ filename, compileOptions }) => {
|
|
110
|
+
* // Dynamically set hydration per Svelte file
|
|
111
|
+
* if (compileWithHydratable(filename) && !compileOptions.hydratable) {
|
|
112
|
+
* return { hydratable: true };
|
|
113
|
+
* }
|
|
114
|
+
* }
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
dynamicCompileOptions?: (data: {
|
|
118
|
+
filename: string;
|
|
119
|
+
code: string;
|
|
120
|
+
compileOptions: Partial<CompileOptions>;
|
|
121
|
+
}) => Promise<Partial<CompileOptions> | void> | Partial<CompileOptions> | void;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* These options are considered experimental and breaking changes to them can occur in any release
|
|
125
|
+
*/
|
|
126
|
+
experimental?: ExperimentalOptions;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export interface SvelteConfig {
|
|
130
|
+
/**
|
|
131
|
+
* A list of file extensions to be compiled by Svelte
|
|
132
|
+
*
|
|
133
|
+
* @default ['.svelte']
|
|
134
|
+
*/
|
|
135
|
+
extensions?: string[];
|
|
136
|
+
/**
|
|
137
|
+
* An array of preprocessors to transform the Svelte source code before compilation
|
|
138
|
+
*
|
|
139
|
+
* @see https://svelte.dev/docs#svelte_preprocess
|
|
140
|
+
*/
|
|
141
|
+
preprocess?: Arrayable<PreprocessorGroup>;
|
|
142
|
+
/**
|
|
143
|
+
* The options to be passed to the Svelte compiler. A few options are set by default,
|
|
144
|
+
* including `dev` and `css`. However, some options are non-configurable, like
|
|
145
|
+
* `filename`, `format`, `generate`, and `cssHash` (in dev).
|
|
146
|
+
*
|
|
147
|
+
* @see https://svelte.dev/docs#svelte_compile
|
|
148
|
+
*/
|
|
149
|
+
compilerOptions?: Omit<CompileOptions, 'filename' | 'format' | 'generate'>;
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Handles warning emitted from the Svelte compiler
|
|
153
|
+
*/
|
|
154
|
+
onwarn?: (warning: Warning, defaultHandler?: (warning: Warning) => void) => void;
|
|
155
|
+
/**
|
|
156
|
+
* Options for vite-plugin-svelte
|
|
157
|
+
*/
|
|
158
|
+
vitePlugin?: PluginOptions;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* These options are considered experimental and breaking changes to them can occur in any release
|
|
163
|
+
*/
|
|
164
|
+
interface ExperimentalOptions {
|
|
165
|
+
/**
|
|
166
|
+
* send a websocket message with svelte compiler warnings during dev
|
|
167
|
+
*
|
|
168
|
+
*/
|
|
169
|
+
sendWarningsToBrowser?: boolean;
|
|
170
|
+
/**
|
|
171
|
+
* disable svelte field resolve warnings
|
|
172
|
+
*
|
|
173
|
+
* @default false
|
|
174
|
+
*/
|
|
175
|
+
disableSvelteResolveWarnings?: boolean;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
type Arrayable<T> = T | T[];
|
|
179
|
+
|
|
180
|
+
export interface VitePreprocessOptions {
|
|
181
|
+
script?: boolean;
|
|
182
|
+
style?: boolean | InlineConfig | ResolvedConfig;
|
|
183
|
+
}
|
|
184
|
+
export function svelte(inlineOptions?: Partial<Options> | undefined): import('vite').Plugin[];
|
|
185
|
+
export function vitePreprocess(opts: VitePreprocessOptions): import('svelte/compiler').PreprocessorGroup;
|
|
186
|
+
export function loadSvelteConfig(viteConfig: import('vite').UserConfig, inlineOptions: Partial<Options>): Promise<Partial<SvelteConfig> | undefined>;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"file": "index.d.ts",
|
|
4
|
+
"names": [
|
|
5
|
+
"Options",
|
|
6
|
+
"SvelteConfig",
|
|
7
|
+
"VitePreprocessOptions",
|
|
8
|
+
"svelte",
|
|
9
|
+
"vitePreprocess",
|
|
10
|
+
"loadSvelteConfig"
|
|
11
|
+
],
|
|
12
|
+
"sources": [
|
|
13
|
+
"../src/public.d.ts",
|
|
14
|
+
"../src/index.js",
|
|
15
|
+
"../src/preprocess.js",
|
|
16
|
+
"../src/utils/load-svelte-config.js"
|
|
17
|
+
],
|
|
18
|
+
"sourcesContent": [
|
|
19
|
+
null,
|
|
20
|
+
null,
|
|
21
|
+
null,
|
|
22
|
+
null
|
|
23
|
+
],
|
|
24
|
+
"mappings": ";;;;;aAMYA,OAAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBA2HFC,YAAYA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAmDZC,qBAAqBA;;;;iBC1JtBC,MAAMA;iBCXNC,cAAcA;iBCgBRC,gBAAgBA"
|
|
25
|
+
}
|