2 ms·
I have a theory that Svelte originated from his work with Rollup. He was already a great developer when he started Rollup, but writing it brought him to a new
by ratww 7y ago
I have a theory that Svelte originated from his work with Rollup.
He was already a great developer when he started Rollup, but writing it brought him to a new level.
Rollup is super clever: most bundlers back then would treat JS modules like giant strings and concatenate them. It was just plain string concatenation, similar to require.js's "define()", so you needed a runtimes that answered to "require()". Modules were assembled during runtime. [1]
Rollup, instead, uses an algorithm to transform the AST of multiple modules into a single AST, inlining all modules and turning them into variables [2], and renaming duplicate identifiers. The final code looks like something that a human would do if asked to put everything in a single file. [3]
This is done by manipulating the AST returned by the Acorn parser, something he seems to have become an expert on.
I'm pretty sure that it was during the development of Rollup that he had other ideas for crazy optimizations, but unable to apply them to a Bundler, he created Svelte.
--
[1] https://requirejs.org/docs/api.html#deffunc https://requirejs.org/docs/api.html#deffunc
[2] https://github.com/rollup/rollup/blob/1e1a11107dbee11636dcf975e57b6ba87cc62c59/src/ast/nodes/ExportDefaultDeclaration.ts#L57 https://github.com/rollup/rollup/blob/1e1a11107dbee11636dcf9... and https://github.com/rollup/rollup/blob/1e1a11107dbee11636dcf975e57b6ba87cc62c59/src/ast/nodes/ExportDefaultDeclaration.ts#L151 https://github.com/rollup/rollup/blob/1e1a11107dbee11636dcf9...
[3] https://risanb.com/posts/bundling-your-javascript-library-with-rollup/#tree-shaking-in-action https://risanb.com/posts/bundling-your-javascript-library-wi...