@sveltejs/vite-plugin-svelte
Advanced tools
Comparing version 2.0.0-beta.2 to 2.0.0-beta.3
@@ -1,3 +0,2 @@ | ||
import * as vite from 'vite'; | ||
import { UserConfig, Plugin } from 'vite'; | ||
import { InlineConfig, ResolvedConfig, UserConfig, Plugin } from 'vite'; | ||
import { CompileOptions, Warning } from 'svelte/types/compiler/interfaces'; | ||
@@ -129,10 +128,2 @@ export { CompileOptions, Warning } from 'svelte/types/compiler/interfaces'; | ||
/** | ||
* Use extra preprocessors that delegate style and TypeScript preprocessing to native Vite plugins | ||
* | ||
* Do not use together with `svelte-preprocess`! | ||
* | ||
* @default false | ||
*/ | ||
useVitePreprocess?: boolean; | ||
/** | ||
* A function to update `compilerOptions` before compilation | ||
@@ -251,3 +242,3 @@ * | ||
script?: boolean; | ||
style?: boolean | vite.InlineConfig | vite.ResolvedConfig; | ||
style?: boolean | InlineConfig | ResolvedConfig; | ||
}): PreprocessorGroup; | ||
@@ -254,0 +245,0 @@ |
{ | ||
"name": "@sveltejs/vite-plugin-svelte", | ||
"version": "2.0.0-beta.2", | ||
"version": "2.0.0-beta.3", | ||
"license": "MIT", | ||
@@ -53,3 +53,3 @@ "author": "dominikg", | ||
"@types/debug": "^4.1.7", | ||
"esbuild": "^0.16.1", | ||
"esbuild": "^0.16.3", | ||
"rollup": "^2.79.1", | ||
@@ -56,0 +56,0 @@ "svelte": "^3.54.0", |
@@ -92,3 +92,2 @@ import fs from 'fs'; | ||
// Vite's optimizer runs after `buildStart()`. | ||
// TODO: verify this works in vite3 | ||
viteConfig.optimizeDeps.force = true; | ||
@@ -95,0 +94,0 @@ } |
import path from 'path'; | ||
import * as vite from 'vite'; | ||
import type { ESBuildOptions, ResolvedConfig } from 'vite'; | ||
import { preprocessCSS, resolveConfig, transformWithEsbuild } from 'vite'; | ||
import type { ESBuildOptions, InlineConfig, ResolvedConfig } from 'vite'; | ||
// eslint-disable-next-line node/no-missing-import | ||
@@ -12,3 +12,3 @@ import type { Preprocessor, PreprocessorGroup } from 'svelte/types/compiler/preprocess'; | ||
script?: boolean; | ||
style?: boolean | vite.InlineConfig | vite.ResolvedConfig; | ||
style?: boolean | InlineConfig | ResolvedConfig; | ||
}) { | ||
@@ -31,3 +31,3 @@ const preprocessor: PreprocessorGroup = {}; | ||
if (!supportedScriptLangs.includes(lang)) return; | ||
const transformResult = await vite.transformWithEsbuild(content, filename, { | ||
const transformResult = await transformWithEsbuild(content, filename, { | ||
loader: lang as ESBuildOptions['loader'], | ||
@@ -51,3 +51,3 @@ target: 'esnext', | ||
function viteStyle(config: vite.InlineConfig | vite.ResolvedConfig = {}): { | ||
function viteStyle(config: InlineConfig | ResolvedConfig = {}): { | ||
style: Preprocessor; | ||
@@ -60,3 +60,3 @@ } { | ||
if (!transform) { | ||
let resolvedConfig: vite.ResolvedConfig; | ||
let resolvedConfig: ResolvedConfig; | ||
// @ts-expect-error special prop added if running in v-p-s | ||
@@ -69,3 +69,3 @@ if (style.__resolvedConfig) { | ||
} else { | ||
resolvedConfig = await vite.resolveConfig( | ||
resolvedConfig = await resolveConfig( | ||
config, | ||
@@ -97,24 +97,9 @@ process.env.NODE_ENV === 'production' ? 'build' : 'serve' | ||
function getCssTransformFn(config: ResolvedConfig): CssTransform { | ||
// API is only available in Vite 3.2 and above | ||
// TODO: Remove Vite plugin hack when bump peer dep to Vite 3.2 | ||
if (vite.preprocessCSS) { | ||
return async (code, filename) => { | ||
return vite.preprocessCSS(code, filename, config); | ||
}; | ||
} else { | ||
const pluginName = 'vite:css'; | ||
const plugin = config.plugins.find((p) => p.name === pluginName); | ||
if (!plugin) { | ||
throw new Error(`failed to find plugin ${pluginName}`); | ||
} | ||
if (!plugin.transform) { | ||
throw new Error(`plugin ${pluginName} has no transform`); | ||
} | ||
// @ts-expect-error | ||
return plugin.transform.bind(null); | ||
} | ||
return async (code, filename) => { | ||
return preprocessCSS(code, filename, config); | ||
}; | ||
} | ||
function isResolvedConfig(config: any): config is vite.ResolvedConfig { | ||
function isResolvedConfig(config: any): config is ResolvedConfig { | ||
return !!config.inlineConfig; | ||
} |
@@ -684,11 +684,2 @@ /* eslint-disable no-unused-vars */ | ||
/** | ||
* Use extra preprocessors that delegate style and TypeScript preprocessing to native Vite plugins | ||
* | ||
* Do not use together with `svelte-preprocess`! | ||
* | ||
* @default false | ||
*/ | ||
useVitePreprocess?: boolean; | ||
/** | ||
* A function to update `compilerOptions` before compilation | ||
@@ -695,0 +686,0 @@ * |
import type { ResolvedConfig, Plugin } from 'vite'; | ||
import MagicString from 'magic-string'; | ||
import { preprocess } from 'svelte/compiler'; | ||
import { PreprocessorGroup, ResolvedOptions } from './options'; | ||
import { log } from './log'; | ||
import path from 'path'; | ||
import { vitePreprocess } from '../preprocess'; | ||
function createVitePreprocessorGroup(config: ResolvedConfig): PreprocessorGroup { | ||
return { | ||
markup({ content, filename }) { | ||
return preprocess(content, vitePreprocess({ style: config }), { filename }); | ||
} | ||
}; | ||
} | ||
/** | ||
@@ -43,9 +33,2 @@ * this appends a *{} rule to component styles to force the svelte compiler to add style classes to all nodes | ||
if (options.experimental?.useVitePreprocess) { | ||
log.warn( | ||
'`experimental.useVitePreprocess` is deprecated. Use the `vitePreprocess()` preprocessor instead. See https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/preprocess.md for more information.' | ||
); | ||
prependPreprocessors.push(createVitePreprocessorGroup(config)); | ||
} | ||
// @ts-ignore | ||
@@ -52,0 +35,0 @@ const pluginsWithPreprocessorsDeprecated = config.plugins.filter((p) => p?.sveltePreprocess); |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
360840
5670