New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: Move to native modules #1165
Comments
@matthewp i have worked exactly on this since 1,5 years :) i am happy that you join this effort |
we should drop steal complet and replace it with rollup i know you love steal but rollup already produces the needed SystemJS Packages and also iife and umd we should make that tool chain work as best and easy as possible via on the long run we should replace stache files and component files with nativ mjs files #1153 is related
at present a good feature detection that handels only the cases that are needed for canjs is missing but can be done relativ easy with more effort |
Does this form of addressing preclude modules installed anywhere other than the top-level To be developed individually, projects would need to have their code moved (or some other solution):
How does native modules solve these problems? |
An alternative I've been thinking about is to embrace using unpkg directly which side-steps the version problem with using locally installed node modules. Maybe a steal-tools export build that produces:
instead of: import canReflect from "../node_modules/can-reflect/can-reflect.js";
import callbacks from "../node_modules/can-view-callbacks/can-view-callbacks.js"; The version numbers inserted into the URL would be taken from the package.json. As a compliment to the above I'd want a service worker for development usage that caches URLs coming from unpkg so you could still develop on an airplane and refreshes should be fast. |
tldr; Make native web modules the primary way we show usage of CanJS and DoneJS.
Problem
Using Steal for development has the following problems:
Solution
Switching all of canjs to use native module imports. For example, where a module might currently look like this:
Change it to:
For end users we would recommend that people install and use
can
. They can avoid these nested imports by creating acan.js
file in their own projects. For example insrc/can.js
it would be:And then in their components, say
components/home.js
they would do:Templating
Since the web doesn't support loading non-JS files, we can't support loading of
.stache
files like we do with steal. However we have already begun showing templates being defined in JavaScript. I think we just continue to do this.For syntax highlighting, there are editor plugins that help with this. For example this one allows you to get HTML highlighting with a comment:
Styling
As with templates, you cannot import a CSS file in native JavaScript modules. We should still continue to suggest using the modlet pattern. To bundle CSS files there are a few possibilities:
Simple concatenation works most of the time.
Using Sass or less or whatever will handler bundling.
If we move to using shadow DOM then inlining styles in a component's template will be required anyways:
Some other solution. For example we could create a "loader" for styles that works like this:
I think we should just pick one of these for the next DoneJS version and incorporate it into the tooling.
Server-side rendering
Node.js doesn't support native modules and likely won't for quite a while (another year at least). Because of this we will need to transpile to CommonJS.
To make this work we can incorporate commonjs exporting (which steal-tools can already do) into
donejs develop
. For example:steal-tools export --cjs
Will export the project to
dist/cjs/
folder. done-ssr can be changed to check this folder in order to load code before falling back to its existing steal loader. In this way, it will not be a breaking change for done-ssr.Production
We should continue to support steal and steal-tools for production use, where bundling is still usually required.
We should explore bundling to native modules so that the loader (whether the steal or slim loader) can be excluded.
Roadmap
This transition cannot occur until some proper tool is developed to make it possible:
stealjs/transpile
.steal-tools export
to support ES transpilation.test.html
file to use native module loading instead (<script type="module">
).es-module
so that it can be tested incanjs/canjs
.dist/cjs/
convention in done-ssr.The text was updated successfully, but these errors were encountered: