-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Description
The "Hello World" app
<h1>Hello world!</h1>
generates quite a bit of boilerplate JS:
/* App.svelte generated by Svelte v3.20.1 */
import {
SvelteComponent,
detach,
element,
init,
insert,
noop,
safe_not_equal
} from "svelte/internal";
function create_fragment(ctx) {
let h1;
return {
c() {
h1 = element("h1");
h1.textContent = "Hello world!";
},
m(target, anchor) {
insert(target, h1, anchor);
},
p: noop,
i: noop,
o: noop,
d(detaching) {
if (detaching) detach(h1);
}
};
}
class App extends SvelteComponent {
constructor(options) {
super();
init(this, options, null, create_fragment, safe_not_equal, {});
}
}
export default App;
For something this simple I believe much of this can be eliminated. Ideally, there should be no JS in this case or whenever the component does not use any external data or bound to components which the data can change.
The rendered or partially rendered components can be stored in another file type and weaved together at compile time. Also, partial evaluation, tree shaking and other optimisations of the Svelte code can be done so the Svelte code used is also minimal perhaps like in Prepack and Closure Compiler restricted to the language used in Svelte. A similar further phase of optimisation can be done in the resulting JS code along with any linked JS libraries to eliminate and optimise the final projects JS code.
This will further optimise the framework.
When it is external data or bound to fields which data can change then the minimal plumbing to accommodate this should be generated.