Skip to content

Remove svelte/ssr resolving #176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/vite-plugin-svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
},
"peerDependencies": {
"diff-match-patch": "^1.0.5",
"svelte": "^3.34.0",
"svelte": "^3.43.0",
"vite": "^2.5.3"
},
"peerDependenciesMeta": {
Expand Down
22 changes: 0 additions & 22 deletions packages/vite-plugin-svelte/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { VitePluginSvelteCache } from './utils/vite-plugin-svelte-cache';
import { ensureWatchedFile, setupWatchers } from './utils/watch';
import { resolveViaPackageJsonSvelte } from './utils/resolve';
import { addExtraPreprocessors } from './utils/preprocess';
import { PartialResolvedId } from 'rollup';

export function svelte(inlineOptions?: Partial<Options>): Plugin {
if (process.env.DEBUG != null) {
Expand All @@ -37,8 +36,6 @@ export function svelte(inlineOptions?: Partial<Options>): Plugin {
) => Promise<CompileData>;
/* eslint-enable no-unused-vars */

let resolvedSvelteSSR: Promise<PartialResolvedId | null>;

return {
name: 'vite-plugin-svelte',
// make sure our resolver runs before vite internal resolver to resolve svelte field correctly
Expand Down Expand Up @@ -104,25 +101,6 @@ export function svelte(inlineOptions?: Partial<Options>): Plugin {
return importee; // query with svelte tag, an id we generated, no need for further analysis
}

if (ssr && importee === 'svelte') {
if (!resolvedSvelteSSR) {
resolvedSvelteSSR = this.resolve('svelte/ssr', undefined, { skipSelf: true }).then(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since Vite can't resolve svelte to the node exports, I wonder if we should revert this file change, and swap out svelte/ssr to svelte, so that we "help" Vite out to resolve it. IIRC this.resolve, which uses the resolver plugin has support for exports map, so it should work. But I could completely wrong.

If so, I think we should left using svelte/ssr at the meantime

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benmccann Nevermind, tested this and it doesn't work

(svelteSSR) => {
log.debug('resolved svelte to svelte/ssr');
return svelteSSR;
},
(err) => {
log.debug(
'failed to resolve svelte to svelte/ssr. Update svelte to a version that exports it',
err
);
return null; // returning null here leads to svelte getting resolved regularly
}
);
}
return resolvedSvelteSSR;
}

try {
const resolved = resolveViaPackageJsonSvelte(importee, importer);
if (resolved) {
Expand Down
1 change: 0 additions & 1 deletion packages/vite-plugin-svelte/src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export const SVELTE_IMPORTS = [
'svelte/easing',
'svelte/internal',
'svelte/motion',
'svelte/ssr',
'svelte/store',
'svelte/transition',
'svelte'
Expand Down
7 changes: 2 additions & 5 deletions packages/vite-plugin-svelte/src/utils/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,8 @@ function buildOptimizeDepsForSvelte(
);
};
if (!isExcluded('svelte')) {
const svelteImportsToInclude = SVELTE_IMPORTS.filter((x) => x !== 'svelte/ssr'); // not used on clientside
log.debug(
`adding bare svelte packages to optimizeDeps.include: ${svelteImportsToInclude.join(', ')} `
);
include.push(...svelteImportsToInclude.filter((x) => !isIncluded(x)));
log.debug(`adding bare svelte packages to optimizeDeps.include: ${SVELTE_IMPORTS.join(', ')} `);
include.push(...SVELTE_IMPORTS.filter((x) => !isIncluded(x)));
} else {
log.debug('"svelte" is excluded in optimizeDeps.exclude, skipped adding it to include.');
}
Expand Down