@sveltejs/vite-plugin-svelte 1.0.0-next.44 → 1.0.0-next.47
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/dist/index.cjs +27 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +8 -4
- package/dist/index.js +25 -11
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
- package/src/index.ts +2 -0
- package/src/ui/inspector/Inspector.svelte +1 -1
- package/src/ui/inspector/plugin.ts +1 -1
- package/src/utils/__tests__/dependencies.spec.ts +7 -4
- package/src/utils/__tests__/sourcemap.spec.ts +1 -0
- package/src/utils/compile.ts +2 -1
- package/src/utils/load-svelte-config.ts +12 -8
- package/src/utils/options.ts +26 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Plugin } from 'vite';
|
|
1
|
+
import { UserConfig, Plugin } from 'vite';
|
|
2
2
|
import { CompileOptions, Warning } from 'svelte/types/compiler/interfaces';
|
|
3
3
|
export { CompileOptions, Warning } from 'svelte/types/compiler/interfaces';
|
|
4
4
|
import { PreprocessorGroup } from 'svelte/types/compiler/preprocess';
|
|
@@ -46,11 +46,13 @@ interface Options {
|
|
|
46
46
|
*/
|
|
47
47
|
emitCss?: boolean;
|
|
48
48
|
/**
|
|
49
|
-
* The options to be passed to the Svelte compiler
|
|
49
|
+
* The options to be passed to the Svelte compiler. A few options are set by default,
|
|
50
|
+
* including `dev` and `css`. However, some options are non-configurable, like
|
|
51
|
+
* `filename`, `format`, `generate`, and `cssHash` (in dev).
|
|
50
52
|
*
|
|
51
53
|
* @see https://svelte.dev/docs#svelte_compile
|
|
52
54
|
*/
|
|
53
|
-
compilerOptions?: CompileOptions
|
|
55
|
+
compilerOptions?: Omit<CompileOptions, 'filename' | 'format' | 'generate'>;
|
|
54
56
|
/**
|
|
55
57
|
* Handles warning emitted from the Svelte compiler
|
|
56
58
|
*/
|
|
@@ -198,6 +200,8 @@ declare type ModuleFormat = NonNullable<CompileOptions['format']>;
|
|
|
198
200
|
declare type CssHashGetter = NonNullable<CompileOptions['cssHash']>;
|
|
199
201
|
declare type Arrayable<T> = T | T[];
|
|
200
202
|
|
|
203
|
+
declare function loadSvelteConfig(viteConfig?: UserConfig, inlineOptions?: Partial<Options>): Promise<Partial<Options> | undefined>;
|
|
204
|
+
|
|
201
205
|
declare function svelte(inlineOptions?: Partial<Options>): Plugin[];
|
|
202
206
|
|
|
203
|
-
export { Arrayable, CssHashGetter, ModuleFormat, Options, svelte };
|
|
207
|
+
export { Arrayable, CssHashGetter, ModuleFormat, Options, loadSvelteConfig, svelte };
|
package/dist/index.js
CHANGED
|
@@ -280,7 +280,8 @@ var _createCompileSvelte = (makeHot) => async function compileSvelte2(svelteRequ
|
|
|
280
280
|
const dependencies = [];
|
|
281
281
|
const compileOptions = __spreadProps(__spreadValues({}, options.compilerOptions), {
|
|
282
282
|
filename,
|
|
283
|
-
generate: ssr ? "ssr" : "dom"
|
|
283
|
+
generate: ssr ? "ssr" : "dom",
|
|
284
|
+
format: "esm"
|
|
284
285
|
});
|
|
285
286
|
if (options.hot && options.emitCss) {
|
|
286
287
|
const hash = `s-${safeBase64Hash(normalizedFilename)}`;
|
|
@@ -456,9 +457,9 @@ var knownSvelteConfigNames = [
|
|
|
456
457
|
"svelte.config.cjs",
|
|
457
458
|
"svelte.config.mjs"
|
|
458
459
|
];
|
|
459
|
-
var dynamicImportDefault = new Function("path", 'return import(path + "?t=" +
|
|
460
|
+
var dynamicImportDefault = new Function("path", "timestamp", 'return import(path + "?t=" + timestamp).then(m => m.default)');
|
|
460
461
|
async function loadSvelteConfig(viteConfig, inlineOptions) {
|
|
461
|
-
if (inlineOptions.configFile === false) {
|
|
462
|
+
if ((inlineOptions == null ? void 0 : inlineOptions.configFile) === false) {
|
|
462
463
|
return;
|
|
463
464
|
}
|
|
464
465
|
const configFile = findConfigToLoad(viteConfig, inlineOptions);
|
|
@@ -466,7 +467,7 @@ async function loadSvelteConfig(viteConfig, inlineOptions) {
|
|
|
466
467
|
let err;
|
|
467
468
|
if (configFile.endsWith(".js") || configFile.endsWith(".mjs")) {
|
|
468
469
|
try {
|
|
469
|
-
const result = await dynamicImportDefault(pathToFileURL(configFile).href);
|
|
470
|
+
const result = await dynamicImportDefault(pathToFileURL(configFile).href, fs2.statSync(configFile).mtimeMs);
|
|
470
471
|
if (result != null) {
|
|
471
472
|
return __spreadProps(__spreadValues({}, result), {
|
|
472
473
|
configFile
|
|
@@ -502,8 +503,8 @@ async function loadSvelteConfig(viteConfig, inlineOptions) {
|
|
|
502
503
|
}
|
|
503
504
|
}
|
|
504
505
|
function findConfigToLoad(viteConfig, inlineOptions) {
|
|
505
|
-
const root = viteConfig.root || process.cwd();
|
|
506
|
-
if (inlineOptions.configFile) {
|
|
506
|
+
const root = (viteConfig == null ? void 0 : viteConfig.root) || process.cwd();
|
|
507
|
+
if (inlineOptions == null ? void 0 : inlineOptions.configFile) {
|
|
507
508
|
const abolutePath = path.isAbsolute(inlineOptions.configFile) ? inlineOptions.configFile : path.resolve(root, inlineOptions.configFile);
|
|
508
509
|
if (!fs2.existsSync(abolutePath)) {
|
|
509
510
|
throw new Error(`failed to find svelte config file ${abolutePath}.`);
|
|
@@ -1083,10 +1084,7 @@ async function preResolveOptions(inlineOptions = {}, viteUserConfig, viteEnv) {
|
|
|
1083
1084
|
});
|
|
1084
1085
|
const defaultOptions = {
|
|
1085
1086
|
extensions: [".svelte"],
|
|
1086
|
-
emitCss: true
|
|
1087
|
-
compilerOptions: {
|
|
1088
|
-
format: "esm"
|
|
1089
|
-
}
|
|
1087
|
+
emitCss: true
|
|
1090
1088
|
};
|
|
1091
1089
|
const svelteConfig = await loadSvelteConfig(viteConfigWithResolvedRoot, inlineOptions);
|
|
1092
1090
|
const extraOptions = {
|
|
@@ -1123,6 +1121,7 @@ function resolveOptions(preResolveOptions2, viteConfig) {
|
|
|
1123
1121
|
isProduction: viteConfig.isProduction
|
|
1124
1122
|
};
|
|
1125
1123
|
const merged = mergeConfigs(defaultOptions, preResolveOptions2, extraOptions);
|
|
1124
|
+
removeIgnoredOptions(merged);
|
|
1126
1125
|
addExtraPreprocessors(merged, viteConfig);
|
|
1127
1126
|
enforceOptionsForHmr(merged);
|
|
1128
1127
|
enforceOptionsForProduction(merged);
|
|
@@ -1171,6 +1170,20 @@ function enforceOptionsForProduction(options) {
|
|
|
1171
1170
|
}
|
|
1172
1171
|
}
|
|
1173
1172
|
}
|
|
1173
|
+
function removeIgnoredOptions(options) {
|
|
1174
|
+
const ignoredCompilerOptions = ["generate", "format", "filename"];
|
|
1175
|
+
if (options.hot && options.emitCss) {
|
|
1176
|
+
ignoredCompilerOptions.push("cssHash");
|
|
1177
|
+
}
|
|
1178
|
+
const passedCompilerOptions = Object.keys(options.compilerOptions || {});
|
|
1179
|
+
const passedIgnored = passedCompilerOptions.filter((o) => ignoredCompilerOptions.includes(o));
|
|
1180
|
+
if (passedIgnored.length) {
|
|
1181
|
+
log.warn(`The following Svelte compilerOptions are controlled by vite-plugin-svelte and essential to its functionality. User-specified values are ignored. Please remove them from your configuration: ${passedIgnored.join(", ")}`);
|
|
1182
|
+
passedIgnored.forEach((ignored) => {
|
|
1183
|
+
delete options.compilerOptions[ignored];
|
|
1184
|
+
});
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1174
1187
|
function resolveViteRoot(viteConfig) {
|
|
1175
1188
|
return normalizePath2(viteConfig.root ? path4.resolve(viteConfig.root) : process.cwd());
|
|
1176
1189
|
}
|
|
@@ -1542,7 +1555,7 @@ function svelteInspector() {
|
|
|
1542
1555
|
disabled = true;
|
|
1543
1556
|
} else {
|
|
1544
1557
|
if (vps.api.options.kit && !inspectorOptions.appendTo) {
|
|
1545
|
-
const out_dir = vps.api.options.kit.outDir || ".svelte-kit";
|
|
1558
|
+
const out_dir = path8.basename(vps.api.options.kit.outDir || ".svelte-kit");
|
|
1546
1559
|
inspectorOptions.appendTo = `${out_dir}/runtime/client/start.js`;
|
|
1547
1560
|
}
|
|
1548
1561
|
appendTo = inspectorOptions.appendTo;
|
|
@@ -1746,6 +1759,7 @@ function svelte(inlineOptions) {
|
|
|
1746
1759
|
return plugins.filter(Boolean);
|
|
1747
1760
|
}
|
|
1748
1761
|
export {
|
|
1762
|
+
loadSvelteConfig,
|
|
1749
1763
|
svelte
|
|
1750
1764
|
};
|
|
1751
1765
|
//# sourceMappingURL=index.js.map
|