Comments (11)
I've been thinking it'd be good if the compiler had an externalHelpers: true
mode that build tools could opt in to (i.e. you probably wouldn't want it for a standalone widget you were shipping, but it definitely makes sense for an app).
The same could apply to methods that don't differ between components, e.g. observe
and the events stuff. (Though at that point you'd need to store callbacks under this
, obviously.)
Basically, what Babel does – marking which helpers are used then either injecting them or importing them depending on the externalHelpers
option. Progressive enhancement stuff would almost certainly fall under that category
from svelte.
Good catch, thanks – will add the fix to #219
from svelte.
It would be nice to have a mode that outputs just the generated code for dom manipulation (create, update, teardown), so the user can choose whatever state management library they would like (eg. mobx)
Not sure how that would best interact with nested components though.
from svelte.
Looking at progressive enhancement, I think it would be particularly useful to have a little bit of library code that could handle walking through the existing DOM to find a valid target and get it into the correct state.
from svelte.
Implemented as of 1.5.0 – build tool integrations will need to be updated to take advantage of it though
from svelte.
It looks like the built shared.js
is not included in the 1.5.0 npm package that was published. I think the file needs to be added to the "files"
section of package.json
.
from svelte.
hmm, in my freshly-installed Svelte 1.6.0, I see a shared.js
, but I don't see any of this new code in compiler/svelte.js
. Did that file get updated/published incorrectly, or am I missing something?
from svelte.
Is there any technical reason why cjs modules couldn't be supported as well? Wouldn't
`const { ${names.join( ', ' )} } = require('svelte/shared-cjs.js')`
work as well as
`import { ${names.join( ', ' )} } from 'svelte/shared.js'`
?
from svelte.
Hm. Producing a shared-cjs.js
would be as simple as adding a new Rollup config for the new built target. And having the Svelte compiler output different code for this depending on the format:
option that was passed to it seems like a good idea.
As for your other issue, 1.6.0 is working fine for me with this. My compiler/svelte.js
has all the new code supporting using the external shared.js
.
from svelte.
I don't see any of this new code in
compiler/svelte.js
that's weird... it should be there, starting at line 6967 of https://unpkg.com/[email protected]/compiler/svelte.js. That not the case for your installation?
Is there any technical reason why cjs modules couldn't be supported as well?
Not really, though if we were doing cjs then we should probably do all the others, and that means treating them the same as other dependencies i.e. passing them in to the define
call for AMD/UMD, etc etc.
And Svelte generates ES5, so couldn't use destructuring – would have to have a temporary variable and do var appendNode = shared.appendNode
, etc...
And we'd need to have CJS and AMD and script tag builds of the shared helpers (or a UMD build).
So I looked at all those considerations and thought 'it's not worth the extra complexity' – since the only people who would be using shared helpers are using bundlers, and if your bundler doesn't natively support ES modules at the end of 2016 then it's probably time to find another bundler 😀
from svelte.
CJS modules
Fair enough. It's true, I can add es2015-modules-commonjs
to babel, I just rarely need to. Not a big deal though.
1.6.0 published correctly
baaaaaah I see what was going on. I'd been reading the new code in #215 and was looking for references to "standalone" in the output code. I see now that it changed from "standalone" to "shared" in #219.
from svelte.
Related Issues (20)
- A11y: add attribute hints for `role="tab"` and `role="tabpanel"` HOT 1
- Use standard `for` and `if` with non-reactive variables
- Collapse inlined variables into templates
- Reactivity lost on $state from class when said $state is consumed in another project (micro-frontend) HOT 11
- Svelte 5: #await block is evaluated after component is no longer rendered HOT 2
- Svelte 5: `$inspect` make `$effect` run syncronously HOT 6
- Custom Elements can have a tag name ending with a hyphen HOT 1
- Svelte 5: event handlers are case-sensitive HOT 3
- `$derived.by` destructor support (Svelte 5) HOT 18
- Nested effect runs twice on state update when wrapped in template effect HOT 4
- Document best practise for unittesting HOT 1
- Better effect stack logging HOT 2
- Parsing error corner case with the `$` and `{` characters
- add typings for svelte/events on(document, on(window
- Track binding values HOT 2
- Can we have specific types for reactive state in Svelte 5? HOT 1
- Svelte 5: Action parameters type inferred as 'any' despite explicit typing
- `class:`/`style:` directives can be overridden by `class`/`style` attributes HOT 4
- Declarative Shadow DOM doesn't work HOT 5
- migrate: Merging event handlers adds an unnecessary parameter HOT 18
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from svelte.