@sveltejs/vite-plugin-svelte 1.0.0-next.9 → 1.0.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/README.md +16 -50
- package/dist/index.cjs +2014 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +231 -214
- package/dist/index.js +1522 -395
- package/dist/index.js.map +1 -0
- package/package.json +48 -33
- package/src/handle-hot-update.ts +117 -0
- package/src/index.ts +242 -0
- package/src/ui/inspector/Inspector.svelte +245 -0
- package/src/ui/inspector/load-inspector.js +15 -0
- package/src/ui/inspector/plugin.ts +106 -0
- package/src/utils/__tests__/dependencies.spec.ts +43 -0
- package/src/utils/__tests__/sourcemap.spec.ts +25 -0
- package/src/utils/compile.ts +159 -0
- package/src/utils/constants.ts +20 -0
- package/src/utils/dependencies.ts +241 -0
- package/src/utils/error.ts +95 -0
- package/src/utils/esbuild.ts +84 -0
- package/src/utils/hash.ts +32 -0
- package/src/utils/id.ts +135 -0
- package/src/utils/load-svelte-config.ts +115 -0
- package/src/utils/log.ts +211 -0
- package/src/utils/optimizer.ts +45 -0
- package/src/utils/options.ts +707 -0
- package/src/utils/preprocess.ts +252 -0
- package/src/utils/resolve.ts +57 -0
- package/src/utils/sourcemap.ts +58 -0
- package/src/utils/vite-plugin-svelte-cache.ts +127 -0
- package/src/utils/watch.ts +110 -0
- package/CHANGELOG.md +0 -44
package/dist/index.d.ts
CHANGED
|
@@ -1,214 +1,231 @@
|
|
|
1
|
-
import { Plugin
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
*
|
|
52
|
-
* @
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
*
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
* @default
|
|
77
|
-
*/
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*/
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
*
|
|
187
|
-
* @default false
|
|
188
|
-
*/
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
1
|
+
import { UserConfig, Plugin } from 'vite';
|
|
2
|
+
import { CompileOptions, Warning } from 'svelte/types/compiler/interfaces';
|
|
3
|
+
export { CompileOptions, Warning } from 'svelte/types/compiler/interfaces';
|
|
4
|
+
import { PreprocessorGroup } from 'svelte/types/compiler/preprocess';
|
|
5
|
+
export { MarkupPreprocessor, Preprocessor, PreprocessorGroup, Processed } from 'svelte/types/compiler/preprocess';
|
|
6
|
+
|
|
7
|
+
declare type Options = Omit<SvelteOptions, 'vitePlugin'> & PluginOptionsInline;
|
|
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
|
+
interface PluginOptions {
|
|
19
|
+
/**
|
|
20
|
+
* A `picomatch` pattern, or array of patterns, which specifies the files the plugin should
|
|
21
|
+
* operate on. By default, all svelte files are included.
|
|
22
|
+
*
|
|
23
|
+
* @see https://github.com/micromatch/picomatch
|
|
24
|
+
*/
|
|
25
|
+
include?: Arrayable<string>;
|
|
26
|
+
/**
|
|
27
|
+
* A `picomatch` pattern, or array of patterns, which specifies the files to be ignored by the
|
|
28
|
+
* plugin. By default, no files are ignored.
|
|
29
|
+
*
|
|
30
|
+
* @see https://github.com/micromatch/picomatch
|
|
31
|
+
*/
|
|
32
|
+
exclude?: Arrayable<string>;
|
|
33
|
+
/**
|
|
34
|
+
* Emit Svelte styles as virtual CSS files for Vite and other plugins to process
|
|
35
|
+
*
|
|
36
|
+
* @default true
|
|
37
|
+
*/
|
|
38
|
+
emitCss?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Enable or disable Hot Module Replacement.
|
|
41
|
+
*
|
|
42
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
43
|
+
*
|
|
44
|
+
* DO NOT CUSTOMIZE SVELTE-HMR OPTIONS UNLESS YOU KNOW EXACTLY WHAT YOU ARE DOING
|
|
45
|
+
*
|
|
46
|
+
* YOU HAVE BEEN WARNED
|
|
47
|
+
*
|
|
48
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
49
|
+
*
|
|
50
|
+
* Set an object to pass custom options to svelte-hmr
|
|
51
|
+
*
|
|
52
|
+
* @see https://github.com/rixo/svelte-hmr#options
|
|
53
|
+
* @default true for development, always false for production
|
|
54
|
+
*/
|
|
55
|
+
hot?: boolean | {
|
|
56
|
+
injectCss?: boolean;
|
|
57
|
+
[key: string]: any;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Some Vite plugins can contribute additional preprocessors by defining `api.sveltePreprocess`.
|
|
61
|
+
* If you don't want to use them, set this to true to ignore them all or use an array of strings
|
|
62
|
+
* with plugin names to specify which.
|
|
63
|
+
*
|
|
64
|
+
* @default false
|
|
65
|
+
*/
|
|
66
|
+
ignorePluginPreprocessors?: boolean | string[];
|
|
67
|
+
/**
|
|
68
|
+
* vite-plugin-svelte automatically handles excluding svelte libraries and reinclusion of their dependencies
|
|
69
|
+
* in vite.optimizeDeps.
|
|
70
|
+
*
|
|
71
|
+
* `disableDependencyReinclusion: true` disables all reinclusions
|
|
72
|
+
* `disableDependencyReinclusion: ['foo','bar']` disables reinclusions for dependencies of foo and bar
|
|
73
|
+
*
|
|
74
|
+
* This should be used for hybrid packages that contain both node and browser dependencies, eg Routify
|
|
75
|
+
*
|
|
76
|
+
* @default false
|
|
77
|
+
*/
|
|
78
|
+
disableDependencyReinclusion?: boolean | string[];
|
|
79
|
+
/**
|
|
80
|
+
* These options are considered experimental and breaking changes to them can occur in any release
|
|
81
|
+
*/
|
|
82
|
+
experimental?: ExperimentalOptions;
|
|
83
|
+
}
|
|
84
|
+
interface SvelteOptions {
|
|
85
|
+
/**
|
|
86
|
+
* A list of file extensions to be compiled by Svelte
|
|
87
|
+
*
|
|
88
|
+
* @default ['.svelte']
|
|
89
|
+
*/
|
|
90
|
+
extensions?: string[];
|
|
91
|
+
/**
|
|
92
|
+
* An array of preprocessors to transform the Svelte source code before compilation
|
|
93
|
+
*
|
|
94
|
+
* @see https://svelte.dev/docs#svelte_preprocess
|
|
95
|
+
*/
|
|
96
|
+
preprocess?: Arrayable<PreprocessorGroup>;
|
|
97
|
+
/**
|
|
98
|
+
* The options to be passed to the Svelte compiler. A few options are set by default,
|
|
99
|
+
* including `dev` and `css`. However, some options are non-configurable, like
|
|
100
|
+
* `filename`, `format`, `generate`, and `cssHash` (in dev).
|
|
101
|
+
*
|
|
102
|
+
* @see https://svelte.dev/docs#svelte_compile
|
|
103
|
+
*/
|
|
104
|
+
compilerOptions?: Omit<CompileOptions, 'filename' | 'format' | 'generate'>;
|
|
105
|
+
/**
|
|
106
|
+
* Handles warning emitted from the Svelte compiler
|
|
107
|
+
*/
|
|
108
|
+
onwarn?: (warning: Warning, defaultHandler?: (warning: Warning) => void) => void;
|
|
109
|
+
/**
|
|
110
|
+
* Options for vite-plugin-svelte
|
|
111
|
+
*/
|
|
112
|
+
vitePlugin?: PluginOptions;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* These options are considered experimental and breaking changes to them can occur in any release
|
|
116
|
+
*/
|
|
117
|
+
interface ExperimentalOptions {
|
|
118
|
+
/**
|
|
119
|
+
* Use extra preprocessors that delegate style and TypeScript preprocessing to native Vite plugins
|
|
120
|
+
*
|
|
121
|
+
* Do not use together with `svelte-preprocess`!
|
|
122
|
+
*
|
|
123
|
+
* @default false
|
|
124
|
+
*/
|
|
125
|
+
useVitePreprocess?: boolean;
|
|
126
|
+
/**
|
|
127
|
+
* Force Vite to pre-bundle Svelte libraries
|
|
128
|
+
*
|
|
129
|
+
* @default false
|
|
130
|
+
*/
|
|
131
|
+
prebundleSvelteLibraries?: boolean;
|
|
132
|
+
/**
|
|
133
|
+
* If a preprocessor does not provide a sourcemap, a best-effort fallback sourcemap will be provided.
|
|
134
|
+
* This option requires `diff-match-patch` to be installed as a peer dependency.
|
|
135
|
+
*
|
|
136
|
+
* @see https://github.com/google/diff-match-patch
|
|
137
|
+
* @default false
|
|
138
|
+
*/
|
|
139
|
+
generateMissingPreprocessorSourcemaps?: boolean;
|
|
140
|
+
/**
|
|
141
|
+
* A function to update `compilerOptions` before compilation
|
|
142
|
+
*
|
|
143
|
+
* `data.filename` - The file to be compiled
|
|
144
|
+
* `data.code` - The preprocessed Svelte code
|
|
145
|
+
* `data.compileOptions` - The current compiler options
|
|
146
|
+
*
|
|
147
|
+
* To change part of the compiler options, return an object with the changes you need.
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```
|
|
151
|
+
* ({ filename, compileOptions }) => {
|
|
152
|
+
* // Dynamically set hydration per Svelte file
|
|
153
|
+
* if (compileWithHydratable(filename) && !compileOptions.hydratable) {
|
|
154
|
+
* return { hydratable: true };
|
|
155
|
+
* }
|
|
156
|
+
* }
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
dynamicCompileOptions?: (data: {
|
|
160
|
+
filename: string;
|
|
161
|
+
code: string;
|
|
162
|
+
compileOptions: Partial<CompileOptions>;
|
|
163
|
+
}) => Promise<Partial<CompileOptions> | void> | Partial<CompileOptions> | void;
|
|
164
|
+
/**
|
|
165
|
+
* enable svelte inspector
|
|
166
|
+
*/
|
|
167
|
+
inspector?: InspectorOptions | boolean;
|
|
168
|
+
/**
|
|
169
|
+
* send a websocket message with svelte compiler warnings during dev
|
|
170
|
+
*
|
|
171
|
+
*/
|
|
172
|
+
sendWarningsToBrowser?: boolean;
|
|
173
|
+
}
|
|
174
|
+
interface InspectorOptions {
|
|
175
|
+
/**
|
|
176
|
+
* define a key combo to toggle inspector,
|
|
177
|
+
* @default 'control-shift' on windows, 'meta-shift' on other os
|
|
178
|
+
*
|
|
179
|
+
* any number of modifiers `control` `shift` `alt` `meta` followed by zero or one regular key, separated by -
|
|
180
|
+
* examples: control-shift, control-o, control-alt-s meta-x control-meta
|
|
181
|
+
* Some keys have native behavior (e.g. alt-s opens history menu on firefox).
|
|
182
|
+
* To avoid conflicts or accidentally typing into inputs, modifier only combinations are recommended.
|
|
183
|
+
*/
|
|
184
|
+
toggleKeyCombo?: string;
|
|
185
|
+
/**
|
|
186
|
+
* inspector is automatically disabled when releasing toggleKeyCombo after holding it for a longpress
|
|
187
|
+
* @default false
|
|
188
|
+
*/
|
|
189
|
+
holdMode?: boolean;
|
|
190
|
+
/**
|
|
191
|
+
* when to show the toggle button
|
|
192
|
+
* @default 'active'
|
|
193
|
+
*/
|
|
194
|
+
showToggleButton?: 'always' | 'active' | 'never';
|
|
195
|
+
/**
|
|
196
|
+
* where to display the toggle button
|
|
197
|
+
* @default top-right
|
|
198
|
+
*/
|
|
199
|
+
toggleButtonPos?: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left';
|
|
200
|
+
/**
|
|
201
|
+
* inject custom styles when inspector is active
|
|
202
|
+
*/
|
|
203
|
+
customStyles?: boolean;
|
|
204
|
+
/**
|
|
205
|
+
* append an import to the module id ending with `appendTo` instead of adding a script into body
|
|
206
|
+
* useful for frameworks that do not support trannsformIndexHtml hook
|
|
207
|
+
*
|
|
208
|
+
* WARNING: only set this if you know exactly what it does.
|
|
209
|
+
* Regular users of vite-plugin-svelte or SvelteKit do not need it
|
|
210
|
+
*/
|
|
211
|
+
appendTo?: string;
|
|
212
|
+
}
|
|
213
|
+
declare type ModuleFormat = NonNullable<CompileOptions['format']>;
|
|
214
|
+
declare type CssHashGetter = NonNullable<CompileOptions['cssHash']>;
|
|
215
|
+
declare type Arrayable<T> = T | T[];
|
|
216
|
+
|
|
217
|
+
declare function loadSvelteConfig(viteConfig?: UserConfig, inlineOptions?: Partial<Options>): Promise<Partial<SvelteOptions> | undefined>;
|
|
218
|
+
|
|
219
|
+
declare type SvelteWarningsMessage = {
|
|
220
|
+
id: string;
|
|
221
|
+
filename: string;
|
|
222
|
+
normalizedFilename: string;
|
|
223
|
+
timestamp: number;
|
|
224
|
+
warnings: Warning[];
|
|
225
|
+
allWarnings: Warning[];
|
|
226
|
+
rawWarnings: Warning[];
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
declare function svelte(inlineOptions?: Partial<Options>): Plugin[];
|
|
230
|
+
|
|
231
|
+
export { Arrayable, CssHashGetter, ModuleFormat, Options, PluginOptions, SvelteOptions, SvelteWarningsMessage, loadSvelteConfig, svelte };
|