Repository navigation
Conversation
Co-Authored-By: Drini Cami <cdrini@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1603 +/- ##
=======================================
Coverage 64.18% 64.18%
=======================================
Files 69 69
Lines 6290 6290
Branches 1398 1398
=======================================
Hits 4037 4037
Misses 2214 2214
Partials 39 39 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Co-Authored-By: Drini Cami <cdrini@gmail.com>
Co-Authored-By: Drini Cami <cdrini@gmail.com>
Co-Authored-By: Drini Cami <cdrini@gmail.com>
|
Woohoo! |
jbuckner
left a comment
There was a problem hiding this comment.
Looks good. I built the esm output and ran it in offshoot (Chromium and WebKit, dev and prod Vite builds). The reader renders, all the plugins register including text selection, and there are no custom element errors. Two small things inline.
| 'plugins/plugin.tts.js': { import: './src/plugins/tts/plugin.tts.js', dependOn: 'BookReader.js' }, | ||
| 'plugins/plugin.url.js': { import: './src/plugins/url/plugin.url.js', dependOn: 'BookReader.js' }, | ||
| 'plugins/plugin.vendor-fullscreen.js': { import: './src/plugins/plugin.vendor-fullscreen.js', dependOn: 'BookReader.js' }, | ||
| 'ia-bookreader-bundle.js': { import: './src/ia-bookreader/ia-bookreader.js', dependOn: 'BookReader.js' }, |
There was a problem hiding this comment.
This bundle defines ia-bookreader and about 9 other ia-* elements with no guard. If a consumer imports this and also imports the package root (src/ia-bookreader), they get registered twice and it throws. Offshoot already imports the package root, so it can't use this file. Can we say that in the PR description? It's one or the other.
There was a problem hiding this comment.
Oh interesting I thought the bundle should not have any of the third-party deps bundled in 🤔 Will give it a test.
| // themselves (e.g. with Vite) rather than loading it via <script> tags. | ||
| { | ||
| ...shared, | ||
| name: 'esm', |
There was a problem hiding this comment.
Nothing in CI checks this output. The whole point is that the plugins have no customElements.define and the declared deps stay bare imports, so a small check on dist/esm for those two things would stop a regression from slipping through. Fine as a follow-up.
Description
Adds a third webpack build,
esm/, that outputs the same entries (core, plugins,ia-bookreader-bundle.js) as ES modules. This lets apps that bundle BookReader themselves (e.g. offshoot with Vite) load it withimport()instead of<script>tags, without having to compilesrc/and its decorators themselves.Future Work
Technical
importthe core's webpack runtime from../BookReader.js, so they share one module registry, likedependOndoes for the classic build.dependenciesare left as bare imports, so the consumer resolves and dedupes them. Bundled copies of web components (e.g.@internetarchive/icon-sharevia text selection) otherwise throw when they re-register a custom element name the host app already defined.litstays bundled because our 2018-09 Babel decorators only work with lit 2's decorators, while consumers may be on lit 3. Sharing lit would need BR on lit 3 with standard decorators (accessorfields).supports es6-module-dynamic-import(Chrome 63, Firefox 67, Edge 79, Safari 11) rather than the classic build's IE 11 floor, since anything loading this build needs ES modules andimport()anyway.esm/BookReader.jsis 217 KB vs 331 KB at the classic targets.esm/is added tofiles,.gitignoreandclean. The classic build's config is unchanged apart from sharing its entry list with the ESM build.Testing
npx webpack --config-name esmbuilds just this output.@internetarchive/bookreader/esm/BookReader.jsand its plugins: the reader renders and all plugins register, with no custom-element re-registration errors.Screenshots/Videos
N/A
🤖 Generated with Claude Code