Closed ma2ciek closed 11 months ago
Things that cause problems in the code right now:
.js
extensions in import paths (it works in node but not in browsers)The first thing we need to decide is which tool we will use ourselves to prepare the ESM versions of packages before publishing.
Things we should care about are:
index.js
file to each of our packages which re-exports everything so that we end up with a single bundle per package. That would be a breaking change, though.Possible tool options are:
So after a bit of thought, the first sensible options that come to my mind are:
index.js
and get a single bundle per package that works with any bundler, node.js, and browsers.In any case, the remaining blockers are:
This is a really interesting idea and would definitely solve many issues.
However, I can't stop thinking about the blockers:
Things that I think should be fairly easy:
My other thought is that ESM has some common problems to the "adding plugins to builds" problem. Those blockers would concern me in both cases. So I've got a feeling that we'd have to tackle both things at the same time to not end up with a solution for ESM which later won't work for adding plugins to builds.
Each package and even each module in a package can require a CSS file now. If we build this into pure ES modules, we need to bundle that CSS into those files somehow... but how? 100 modules, each adding its own stylesheet to a page. What about common dependencies? What about order of those stylesheets? It's not about code size here β it's about this not blowing up completely.
The first issue is probably solvable. The order of stylesheets could be a much bigger problem.
I could imagine that from such three endpoints with their dependencies:
- A.js
- A.css
- B.js
- B.js
- B.css
- C.js
- B.css
We could generate the following ESM:
- A.js
- A.css.js
- B.js
- B.js
- B.css.js
- C.js
- B.css.js
- A.css.js
- B.css.js
So the CSS output won't be duplicated and will be imported once. However, that might won't work with PostCSS @import
tags. (Though, I think that it might duplicate the CSS code even now)
My other thought is that ESM has some common problems to the "adding plugins to builds" problem. Those blockers would concern me in both cases. So I've got a feeling that we'd have to tackle both things at the same time to not end up with a solution for ESM which later won't work for adding plugins to builds.
The only way to solve the "adding plugins to builds" problem is to kill builds at some point IMHO.
Similar thing for translations. No idea how this could work :(.
Maybe even something like this would do the trick if we collect all available translations:
import { polishTranslations } from '@ckeditor/ckeditor5-translations';
import translationService from '@ckeditor/ckeditor5-utils/src/translation-service';
translationService.add( 'pl', polishTranslations );
ClassicEditor.create( ... )
This way it could be super easy to fill the missing translations by hand if we skip the CKEditorWebpackPlugin:
import { polishTranslations: officialPolishTranslations } from '@ckeditor/ckeditor5-translations';
import translationService from '@ckeditor/ckeditor5-utils/src/translation-service';
translationService.add( 'pl', officialPolishTranslations );
translationService.add( 'pl', { Add: 'Dodaj' } );
Actually this approach is used in other packages as well - https://date-fns.org (i18n example).
The only way to solve the "adding plugins to builds" problem is to kill builds at some point IMHO.
β€οΈ
It seems that the libraryTarget: 'module'
is planned for the webpack 5 release, but it's still not implemented or implemented as an experimental feature - webpack/webpack#9802, https://webpack.js.org/configuration/experiments/#root. It will be interesting to see if it can bring us some value.
There has been no activity on this issue for the past year. We've marked it as stale and will close it in 30 days. We understand it may be relevant, so if you're interested in the solution, leave a comment or reaction under this issue.
We've closed your issue due to inactivity over the last year. We understand that the issue may still be relevant. If so, feel free to open a new one (and link this issue to it).
π Provide a description of the new feature
First, thanks to @phaux for the proposal. Firstly I thought it's impossible, but after a talk, I'd give it a try as the benefits side of this feature is so huge.
The problem
Right now it's very hard to add something to the build without rebuilding it. It makes also the CKEditor 5 project very dependent on the webpack bundler (and on its configuration as well) and creates other issues when it comes to bundling CKEditor 5 sources inside frameworks.
The solution
What if we could just allow users to use ESM and just type the following in the JS file that won't need any bundling / transpilation and will just work in the browser:
Benefits:
<script type="module">
Cons:
Some more technical details:
There're at least three potential problems I'm aware of:
Since all our JS files are documented and can be imported, all our JS files should be entry points during the ESM generation process. SVG files and CSS files that are shared across multiple files should be moved to some shared code chunks.
But... I'm not sure if it gonna work at all πThe ESM building would need to be very precise to not duplicate CSS styles, which I think is the critical issue here.
Waiting for your critical opinions ;)
If you'd like to see this feature implemented, add a π reaction to this post.