Live data from Hacker News

Migrating from Vue 2 to Svelte

escape.tech

161–170 of 289 posts

Re: Migrating from Vue 2 to Svelte

#161

Svelte & SvelteKit has been wonderfully productive for me. It's a bit insane that I have adopted it across so many projects of mine despite the fact it is pre 1.0 (well that has more to do with me I guess), but I am just faster with it. I have used a lot of frontend frameworks over the years, and before SvelteKit Vue & Nuxt were what I was warming up to. The article really focused on measurable things like type check…

Yeah same. My convoluted Vue 2 and React projects are much smaller and easier organized / maintainable as rewritten in Svelte vs. Vue 2.

Until Svelte and Kit becomes difficult, slow, or hard to use, I'll keep using it. No need to switch to another at this point.

I'm even using Kit to build out simple REST API endpoints, it's so simple.

Re: Migrating from Vue 2 to Svelte

#162
post #7

Still don't understand why people prefer magic templated front-end frameworks. Reading non-standard HTML just sucks. What even is "$:" or why does Vue require non-standard javascript ref("") objects...

If you want a serious answer: because frameworks do a lot of work for you. For example, they will keep state synchronised between your data model and components (and with some handy plugins, your server). They allow encapsulation and reuse through a well thought out set of abstractions. They provide functionality like routing and app-wide data stores with transactions. If you’re just building a webpage no problem, us…

I think what snowl wanted to know was more technical than that - why such new syntax is necessary to achieve those things? Why exactly the same things cannot be achieved with existing syntax? For example, it's very understandable why JSX is preferable over vue's string syntax () in terms of "just use JS" argument. What exactly warrants this necessity for these weird looking and non-standard syntaxes and why it can't be done without them. Thank you.

Re: Migrating from Vue 2 to Svelte

#163
post #4

It seems worrisome that front end frameworks needs to be changed after just two years of use. Glad I'm not working with front end...

React is almost 10 years old, if you used React in the last few years you haven't really been changing more than the average backend. The "frontend changes so often" meme made sense years ago but doesn't seem to be that different than backend nowadays. I mean in the last ~10 years we had the new hotness of moving from cloud hosted servers -> docker images -> kubernetes, C# made a massive move when going to .net core,…

But if you picked C and Unix 50 years ago…

Re: Migrating from Vue 2 to Svelte

#164
post #12

Re events - You can type events in Vue with `defineEmits`: https://vuejs.org/api/sfc-script-setup.html#defineprops-defi... Re global enums - I'm not sure what the author means about global enums - anything imported into your Vue file can be used in the ` `. Re styles - Style is automatically scoped in Vue SFC files, too - I believe it was the first component framework to do this. This article and migration seems not…

I've got a couple of templates where I've aliased the value of a TypeScript enum into a local variable before using it in the template, so I'm pretty certain at that point I was unable to use the value of the enum directly (that's also how I remember it). However, I just tried it and...it seems to just work now. So thanks for making me revisit that :D.

[deleted]

Re: Migrating from Vue 2 to Svelte

#165

The very first paragraph leads me to believe this is just a rewrite into svelte for the sake of it - I get it, Svelte is the new hotness on the FE-js-block, but this entire post stinks of "someone on the dev team advocated and fluffed enough figures to convince us. So now we're going to tell you why it was the right choice!" I say all this pretty confidently as someone currently maintaining a massive legacy vue2 app…

SvelteKit (a meta framework) is still not at 1.0, but Svelte itself is at 3.53 and mature and stable. We've used it production for several apps (moving from React). It's been a joy to work with.

Re: Migrating from Vue 2 to Svelte

#166
post #16
post #4

It seems worrisome that front end frameworks needs to be changed after just two years of use. Glad I'm not working with front end...

As another comment mentioned, migrating from Vue 2 to Vue 3 is mostly trivial, so this is probably just a case of preferring the new shiny over the old formerly shiny now slightly tarnished...

I agree but it is not really 'new shiny'. I went from Vue2 to Svelte long time ago. Svelte 1 is from 2016.

Re: Migrating from Vue 2 to Svelte

#167

People jump back and forth between Vue and Svelte (or another JS framework of the year), while Aurelia quietly does its job without too much hype.

Is Aurelia even being actively developed? Aurelia 2 has not reached stable while vue has moved to v3

Re: Migrating from Vue 2 to Svelte

#168
post #116

Earlier quoted context omitted.

JSX compiles down to standard JS

...so does Svelte?

JSX is basically just syntax sugar for:

    createElement(
        "div", {
            className: ["recipeTile", { lastRow: options.lastRow, lastColumn: options.lastColumn }],
            onclick: function () { showHideRecipe(recipe.name) }
        }, [
            createElement("img", { src: "./static/images/" + recipe.name + ".jpg" }),
            createElement("div", { className: "details" }, [
                createElement("div", { className: "name" }, capitalize(recipe.name)),
                createElement("div", { className: "ingredients", }, Object.keys(recipe.ingredients).map(function(ingredientName) {
                    return capitalize(ingredientName);
                }).join(", "))
            ])
        ]
    );

    function createElement(type, attributes, children) {
        var element = document.createElement(type);
    
        Object.keys(attributes).forEach(function(key) {
            if (key === "className") {
                classNames(attributes[key]).forEach(function (className) {
                    element.classList.add(className);
                });
            } else if (key.indexOf("on") === 0) {
                element.addEventListener(key.replace("on", ""), attributes[key], false);
            } else {
                element.setAttribute(key, attributes[key]);
            }
        });
    
        if (Array.isArray(children)) {
            children.forEach(function(child) {
                child && element.appendChild(child);
            });
        } else if (typeof children === "string") {
            element.textContent = children;
        } else if (children) {
            element.appendChild(children);
        }
    
        return element;
    }
Isn't svelte much more than that?

Re: Migrating from Vue 2 to Svelte

#169
post #62

As an infrastructure engineer who sometimes try to write good looking UI for internal dashboards, I don't see much difference between the two. So why not go with the largest community?

Maybe they choose performance over community since Svelte does not use virtual DOM.
Post reply on HN