question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for multiple Svelte versions?

See original GitHub issue

I’ve been working with a very sizable business app that’s been stuck in Svelte 1 land for… a while.

Because it’s reasonably large, transitioning the whole site in one go would be difficult, but it’s all in one project so I’m trying to work out ways to transition chunks to Svelte 3.

With npm v6.9.0 you can alias different versions of the same library, so you could do:

"dependencies": {
   "svelte1": "npm:svelte@1",
   "svelte3": "npm:svelte@3"
}

However, this plugin puts the Svelte version checking at initialization, e.g. in index.js it has:

const { version } = require('svelte/package.json');
// ...
const major_version = +version[0];
// ...
const { compile, preprocess } = major_version >= 3
	? require('svelte/compiler.js')
	: require('svelte');

Proposal?

Imagine if the version of Svelte could be passed in as an option:

import svelte1 from 'svelte1' // through the magic of alias
import svelte3 from 'svelte3'
import sveltePlugin from 'rollup-plugin-svelte'

export default {
  // ...
  plugins: [
    sveltePlugin({
      svelte: svelte1,
      extensions: [ '.html' ]
    }),
    sveltePlugin({
      svelte: svelte3,
      extensions: [ '.svelte' ]
    }),
    // ...

It looks like the compile and preprocess are only used in the returned transform function, so this could be a non-breaking change:

function loadSvelte() {
	const { version } = require('svelte/package.json');
	const major_version = +version[0];
	return major_version >= 3
		? require('svelte/compiler.js')
		: require('svelte');
}
module.exports = function svelte(options = {}) {
	const { compile, preprocess } = options.svelte || loadSvelte()

I think the general idea is sound, but improvements could probably be made.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
lukeedcommented, Oct 20, 2020

Closed via #124 & will be available in 6.1.0

1reaction
tivaccommented, Aug 20, 2020

I built a v2-to-v3 translation library, parts of that night be a useful starting point. We used it for a reasonably large long term port of an existing v2 app to v3.

https://github.com/tivac/svelte-translator

Here’s some details about the port we did using it.

https://twitter.com/tivac/status/1291426619626647557

It actually started life as a v1 app, we ported to v2 using the automated conversion stuff and that was a relatively painless process.

The biggest thing was a simple replacement for this plugin we could use with rollup that was v2 aware, since we didn’t need CSS ha doing it was pretty straightforward.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Docs • Svelte
Using an older version of Svelte? ... The Svelte team maintains a VS Code extension and there are integrations with various other editors...
Read more >
How to have two svelte transitions on the same element ...
1. <script> ; 2. import { fade, slide } from 'svelte/transition'; ; 3. import { tick, afterUpdate, beforeUpdate, onMount } from "svelte" ;...
Read more >
FAQ • Svelte
Frequently Asked Questions · I'm new to Svelte. Where should I start? · Where can I get support? permalink · Is Svelte v2...
Read more >
Accelerating Svelte's Development
Multiple major cloud vendors are stepping up to make deploying SvelteKit ... their zip-it-and-ship-it tool to better support SvelteKit.
Read more >
Svelte <3 TypeScript
To understand the two main parts of TypeScript support, we'll compare it to the ... so if you're using an older version be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found