@sveltejs/vite-plugin-svelte 1.4.0 → 2.0.0-beta.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/vite-plugin-svelte",
3
- "version": "1.4.0",
3
+ "version": "2.0.0-beta.1",
4
4
  "license": "MIT",
5
5
  "author": "dominikg",
6
6
  "files": [
@@ -9,14 +9,11 @@
9
9
  "*.d.ts"
10
10
  ],
11
11
  "type": "module",
12
- "main": "dist/index.cjs",
13
- "module": "dist/index.js",
14
12
  "types": "dist/index.d.ts",
15
13
  "exports": {
16
14
  ".": {
17
15
  "types": "./dist/index.d.ts",
18
- "import": "./dist/index.js",
19
- "require": "./dist/index.cjs"
16
+ "import": "./dist/index.js"
20
17
  },
21
18
  "./package.json": "./package.json",
22
19
  "./src/ui/*": "./src/ui/*"
@@ -43,25 +40,25 @@
43
40
  "debug": "^4.3.4",
44
41
  "deepmerge": "^4.2.2",
45
42
  "kleur": "^4.1.5",
46
- "magic-string": "^0.26.7",
43
+ "magic-string": "^0.27.0",
47
44
  "svelte-hmr": "^0.15.1",
48
45
  "vitefu": "^0.2.2"
49
46
  },
50
47
  "peerDependencies": {
51
- "svelte": "^3.44.0",
52
- "vite": "^3.0.0"
48
+ "svelte": "^3.54.0",
49
+ "vite": "^4.0.0-beta.5"
53
50
  },
54
51
  "devDependencies": {
55
52
  "@types/debug": "^4.1.7",
56
- "esbuild": "^0.15.16",
53
+ "esbuild": "^0.16.1",
57
54
  "rollup": "^2.79.1",
58
- "svelte": "^3.53.1",
55
+ "svelte": "^3.54.0",
59
56
  "tsup": "^6.5.0",
60
- "vite": "^3.2.4"
57
+ "vite": "^4.0.0-beta.5"
61
58
  },
62
59
  "scripts": {
63
60
  "dev": "pnpm build:ci --sourcemap --watch src",
64
- "build:ci": "rimraf dist && tsup-node src/index.ts src/preprocess.ts --format esm,cjs --no-splitting --shims",
61
+ "build:ci": "rimraf dist && tsup-node src/index.ts --format esm",
65
62
  "build": "pnpm build:ci --dts --sourcemap"
66
63
  }
67
64
  }
package/src/index.ts CHANGED
@@ -18,7 +18,6 @@ import {
18
18
 
19
19
  import { ensureWatchedFile, setupWatchers } from './utils/watch';
20
20
  import { resolveViaPackageJsonSvelte } from './utils/resolve';
21
- import { PartialResolvedId } from 'rollup';
22
21
  import { toRollupError } from './utils/error';
23
22
  import { saveSvelteMetadata } from './utils/optimizer';
24
23
  import { svelteInspector } from './ui/inspector/plugin';
@@ -47,9 +46,7 @@ export function svelte(inlineOptions?: Partial<Options>): Plugin[] {
47
46
  let viteConfig: ResolvedConfig;
48
47
  /* eslint-disable no-unused-vars */
49
48
  let compileSvelte: CompileSvelte;
50
- /* eslint-enable no-unused-vars */
51
49
 
52
- let resolvedSvelteSSR: Promise<PartialResolvedId | null>;
53
50
  const api: PluginAPI = {};
54
51
  const plugins: Plugin[] = [
55
52
  {
@@ -136,24 +133,6 @@ export function svelte(inlineOptions?: Partial<Options>): Plugin[] {
136
133
  }
137
134
  }
138
135
 
139
- if (ssr && importee === 'svelte') {
140
- if (!resolvedSvelteSSR) {
141
- resolvedSvelteSSR = this.resolve('svelte/ssr', undefined, { skipSelf: true }).then(
142
- (svelteSSR) => {
143
- log.debug('resolved svelte to svelte/ssr');
144
- return svelteSSR;
145
- },
146
- (err) => {
147
- log.debug(
148
- 'failed to resolve svelte to svelte/ssr. Update svelte to a version that exports it',
149
- err
150
- );
151
- return null; // returning null here leads to svelte getting resolved regularly
152
- }
153
- );
154
- }
155
- return resolvedSvelteSSR;
156
- }
157
136
  //@ts-expect-error scan
158
137
  const scan = !!opts?.scan; // scanner phase of optimizeDeps
159
138
  const isPrebundled =
@@ -5,12 +5,10 @@ import { Compiled } from './compile';
5
5
  import { log } from './log';
6
6
  import { CompileOptions, ResolvedOptions } from './options';
7
7
  import { toESBuildError } from './error';
8
- import { atLeastSvelte } from './svelte-version';
9
8
  import { StatCollection } from './vite-plugin-svelte-stats';
10
9
 
11
10
  type EsbuildOptions = NonNullable<DepOptimizationOptions['esbuildOptions']>;
12
11
  type EsbuildPlugin = NonNullable<EsbuildOptions['plugins']>[number];
13
- const isCssString = atLeastSvelte('3.53.0');
14
12
 
15
13
  export const facadeEsbuildSveltePluginName = 'vite-plugin-svelte:facade';
16
14
 
@@ -53,7 +51,8 @@ async function compileSvelte(
53
51
  ): Promise<string> {
54
52
  let css = options.compilerOptions.css;
55
53
  if (css !== 'none') {
56
- css = isCssString ? 'injected' : true;
54
+ // TODO ideally we'd be able to externalize prebundled styles too, but for now always put them in the js
55
+ css = 'injected';
57
56
  }
58
57
  const compileOptions: CompileOptions = {
59
58
  ...options.compilerOptions,
@@ -30,13 +30,10 @@ import {
30
30
  isDepNoExternaled
31
31
  // eslint-disable-next-line node/no-missing-import
32
32
  } from 'vitefu';
33
- import { atLeastSvelte } from './svelte-version';
33
+
34
34
  import { isCommonDepWithoutSvelteField } from './dependencies';
35
35
  import { VitePluginSvelteStats } from './vite-plugin-svelte-stats';
36
36
 
37
- // svelte 3.53.0 changed compilerOptions.css from boolean to string | boolen, use string when available
38
- const cssAsString = atLeastSvelte('3.53.0');
39
-
40
37
  const allowedPluginOptions = new Set([
41
38
  'include',
42
39
  'exclude',
@@ -182,16 +179,12 @@ export function resolveOptions(
182
179
  preResolveOptions: PreResolvedOptions,
183
180
  viteConfig: ResolvedConfig
184
181
  ): ResolvedOptions {
185
- const css = cssAsString
186
- ? preResolveOptions.emitCss
187
- ? 'external'
188
- : 'injected'
189
- : !preResolveOptions.emitCss;
182
+ const css = preResolveOptions.emitCss ? 'external' : 'injected';
190
183
  const defaultOptions: Partial<Options> = {
191
184
  hot: viteConfig.isProduction
192
185
  ? false
193
186
  : {
194
- injectCss: css === true || css === 'injected',
187
+ injectCss: css === 'injected',
195
188
  partialAccept: !!viteConfig.experimental?.hmrPartialAccept
196
189
  },
197
190
  compilerOptions: {
@@ -235,7 +228,7 @@ function enforceOptionsForHmr(options: ResolvedOptions) {
235
228
  }
236
229
  const css = options.compilerOptions.css;
237
230
  if (css === true || css === 'injected') {
238
- const forcedCss = cssAsString ? 'external' : false;
231
+ const forcedCss = 'external';
239
232
  log.warn(
240
233
  `hmr and emitCss are enabled but compilerOptions.css is ${css}, forcing it to ${forcedCss}`
241
234
  );
@@ -254,7 +247,7 @@ function enforceOptionsForHmr(options: ResolvedOptions) {
254
247
  }
255
248
  const css = options.compilerOptions.css;
256
249
  if (!(css === true || css === 'injected')) {
257
- const forcedCss = cssAsString ? 'injected' : true;
250
+ const forcedCss = 'injected';
258
251
  log.warn(
259
252
  `hmr with emitCss disabled requires compilerOptions.css to be enabled, forcing it to ${forcedCss}`
260
253
  );