-
Notifications
You must be signed in to change notification settings - Fork 788
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
feat(loader): inject import statements that are statically analyzable #2959
feat(loader): inject import statements that are statically analyzable #2959
Conversation
To any requiring this sooner, rather than later I built out a temporary package of all my recent PRs - including this ^. What else: You can test it out with little disruption by just swapping out any reference to @stencil/core in your package.json
in package.json, becomes
I will keep this package in-sync with @stencil/core master up until the relevant PRs get accepted or rejected. |
I am still having this issues after using your changes |
thanks so much for trying it out! |
Update: ^^ This is a good way to get the package :) but it causes the following
Installing without the npm alias produces:
|
@armenr sorry to hear that! |
- upgrade prettier to v2.3.2 - lock version to prevent breaking changes in minor versions - add prettier.dry-run package.json script - add pipeline action to evaluate format status - add prettierignore file for faster runs STENCIL-8: Add Prettier to Stencil
I ran this and it fixed my issue. I needed an extra |
…ing-dyn-imports # Conflicts: # .prettierignore # package-lock.json # package.json # scripts/license.ts # scripts/release-tasks.ts # scripts/release.ts # scripts/utils/release-utils.ts # src/sys/node/node-sys.ts # test/browser-compile/src/utils/css-template-plugin.ts # test/karma/stencil.config.ts # test/karma/test-app/slot-fallback/karma.spec.ts # test/karma/test-app/util.ts
+1 |
+1, this was exactly the problem I was running into via https://github.com/jepiqueau/jeep-sqlite |
Any progress on the merge for this? |
sorry - this is on me - I'm super busy in real life atm. If anyone wants to make a demo repo just showing this PR working with a bunch of different bundlers that can get Ryan what he needs and get this unstuck.. |
I've spun up a repo with webpack, vite, and parcel. The vite production build script uses rollup so that is also kind of demoed. Does this help move things along? |
I've recently switched over to using |
We need it :-) |
thanks! This definitely looks promising. I'll get some time scheduled next sprint to start to circle back to this issue and dive in deeper |
Thanks for the PR with Vite support and @rwaskiewicz for picking it up! Do you have any estimations/updates when the Vite support can be released? |
Thanks so much for tackling this issue. Any updates when it might be merged? It's highly needed. |
…onic-team#2959 adapted the changes from @johnjenkins by ionic-team#2959
@johnjenkins could you please update your branch and release a new npm package as well ? There have been stencil releases in the meantime. |
Hey folks - quick update - we're going to start looking at this during our next sprint (starting this upcoming Monday). |
Any movement on this? |
It would be cool to have this merged in - looking forward for it! |
we're also looking forward for it a lot! Thanks for all your work and please let us know in case of any updates |
Any news on this one? :) |
this commit adds experimental support for using stencil component libraries in projects that use bundlers such as vite. prior to this commit, stencil component libraries that were used in projects that used such bundlers would have issues lazily-loading components at runtime. this is due to restrictions the bundlers themselves place on the filepaths that can be used in dynamic import statements. this commit does not introduce the ability for stencil's compiler to use bundlers other than rollup under the hood. it only permits a compiled component library (that uses the `dist` output target) to be used in an application that uses a bundler built atop of rollup. due to the restrictions that rollup may impose on dynamic imports, this commit adds the ability to add an explicit `import()` statement for each lazily-loadable bundle. in order to keep the runtime small, this feature is hidden behind a new feature flag, `experimentalImportInjection` this pr build's atop the work done by @johnjenkins in #2959 and the test cases provided by @PrinceManfred in #2959 (comment). Without their contributions, this commit would not have been possible. STENCIL-339: Integrate Bundler Functionality
this commit adds experimental support for using stencil component libraries in projects that use bundlers such as vite. prior to this commit, stencil component libraries that were used in projects that used such bundlers would have issues lazily-loading components at runtime. this is due to restrictions the bundlers themselves place on the filepaths that can be used in dynamic import statements. this commit does not introduce the ability for stencil's compiler to use bundlers other than rollup under the hood. it only permits a compiled component library (that uses the `dist` output target) to be used in an application that uses a bundler built atop of rollup. due to the restrictions that rollup may impose on dynamic imports, this commit adds the ability to add an explicit `import()` statement for each lazily-loadable bundle. in order to keep the runtime small, this feature is hidden behind a new feature flag, `experimentalImportInjection` this pr build's atop the work done by @johnjenkins in #2959 and the test cases provided by @PrinceManfred in #2959 (comment). Without their contributions, this commit would not have been possible. STENCIL-339: Integrate Bundler Functionality
* fix(runtime): add lazy load for addtl bundlers this commit adds experimental support for using stencil component libraries in projects that use bundlers such as vite. prior to this commit, stencil component libraries that were used in projects that used such bundlers would have issues lazily-loading components at runtime. this is due to restrictions the bundlers themselves place on the filepaths that can be used in dynamic import statements. this commit does not introduce the ability for stencil's compiler to use bundlers other than rollup under the hood. it only permits a compiled component library (that uses the `dist` output target) to be used in an application that uses a bundler built atop of rollup. due to the restrictions that rollup may impose on dynamic imports, this commit adds the ability to add an explicit `import()` statement for each lazily-loadable bundle. in order to keep the runtime small, this feature is hidden behind a new feature flag, `experimentalImportInjection` this pr build's atop the work done by @johnjenkins in #2959 and the test cases provided by @PrinceManfred in #2959 (comment). Without their contributions, this commit would not have been possible. STENCIL-339: Integrate Bundler Functionality * review(ap): remove unnecessary nested `Promise.all` calls remove two nested `Promise.all` calls - after moving writing lazily loadable chunks out of the outermost `Promise.all` call, we were awaiting a single promise wrapped in an array. this commit simplifies the code
* fix(runtime): add lazy load for addtl bundlers this commit adds experimental support for using stencil component libraries in projects that use bundlers such as vite. prior to this commit, stencil component libraries that were used in projects that used such bundlers would have issues lazily-loading components at runtime. this is due to restrictions the bundlers themselves place on the filepaths that can be used in dynamic import statements. this commit does not introduce the ability for stencil's compiler to use bundlers other than rollup under the hood. it only permits a compiled component library (that uses the `dist` output target) to be used in an application that uses a bundler built atop of rollup. due to the restrictions that rollup may impose on dynamic imports, this commit adds the ability to add an explicit `import()` statement for each lazily-loadable bundle. in order to keep the runtime small, this feature is hidden behind a new feature flag, `experimentalImportInjection` this pr build's atop the work done by @johnjenkins in #2959 and the test cases provided by @PrinceManfred in #2959 (comment). Without their contributions, this commit would not have been possible. STENCIL-339: Integrate Bundler Functionality * review(ap): remove unnecessary nested `Promise.all` calls remove two nested `Promise.all` calls - after moving writing lazily loadable chunks out of the outermost `Promise.all` call, we were awaiting a single promise wrapped in an array. this commit simplifies the code
* fix(runtime): add lazy load for addtl bundlers this commit adds experimental support for using stencil component libraries in projects that use bundlers such as vite. prior to this commit, stencil component libraries that were used in projects that used such bundlers would have issues lazily-loading components at runtime. this is due to restrictions the bundlers themselves place on the filepaths that can be used in dynamic import statements. this commit does not introduce the ability for stencil's compiler to use bundlers other than rollup under the hood. it only permits a compiled component library (that uses the `dist` output target) to be used in an application that uses a bundler built atop of rollup. due to the restrictions that rollup may impose on dynamic imports, this commit adds the ability to add an explicit `import()` statement for each lazily-loadable bundle. in order to keep the runtime small, this feature is hidden behind a new feature flag, `experimentalImportInjection` this pr build's atop the work done by @johnjenkins in #2959 and the test cases provided by @PrinceManfred in #2959 (comment). Without their contributions, this commit would not have been possible. STENCIL-339: Integrate Bundler Functionality * review(ap): remove unnecessary nested `Promise.all` calls remove two nested `Promise.all` calls - after moving writing lazily loadable chunks out of the outermost `Promise.all` call, we were awaiting a single promise wrapped in an array. this commit simplifies the code
* fix(runtime): add lazy load for addtl bundlers this commit adds experimental support for using stencil component libraries in projects that use bundlers such as vite. prior to this commit, stencil component libraries that were used in projects that used such bundlers would have issues lazily-loading components at runtime. this is due to restrictions the bundlers themselves place on the filepaths that can be used in dynamic import statements. this commit does not introduce the ability for stencil's compiler to use bundlers other than rollup under the hood. it only permits a compiled component library (that uses the `dist` output target) to be used in an application that uses a bundler built atop of rollup. due to the restrictions that rollup may impose on dynamic imports, this commit adds the ability to add an explicit `import()` statement for each lazily-loadable bundle. in order to keep the runtime small, this feature is hidden behind a new feature flag, `experimentalImportInjection` this pr build's atop the work done by @johnjenkins in #2959 and the test cases provided by @PrinceManfred in #2959 (comment). Without their contributions, this commit would not have been possible. STENCIL-339: Integrate Bundler Functionality * review(ap): remove unnecessary nested `Promise.all` calls remove two nested `Promise.all` calls - after moving writing lazily loadable chunks out of the outermost `Promise.all` call, we were awaiting a single promise wrapped in an array. this commit simplifies the code
) this commit adds experimental support for using stencil component libraries in projects that use bundlers such as vite. prior to this commit, stencil component libraries that were used in projects that used such bundlers would have issues lazily-loading components at runtime. this is due to restrictions the bundlers themselves place on the filepaths that can be used in dynamic import statements. this commit does not introduce the ability for stencil's compiler to use bundlers other than rollup under the hood. it only permits a compiled component library (that uses the `dist` output target) to be used in an application that uses a bundler built atop of rollup. due to the restrictions that rollup may impose on dynamic imports, this commit adds the ability to add an explicit `import()` statement for each lazily-loadable bundle. in order to keep the runtime small, this feature is hidden behind a new feature flag, `experimentalImportInjection` this pr build's atop the work done by @johnjenkins in #2959 and the test cases provided by @PrinceManfred in #2959 (comment). Without their contributions, this commit would not have been possible. add a stencil component library to be used in tests that verify applications that consume the library and are bundled with vite, parcel, etc. add an application that is built using vite to the bundler test directory. it consumes a small stencil library build using the `dist` output target, and verifies that the application can load the web component when the application has been built using vite. add infrastructure for running the bundler tests in karma. karma was chosen to align with existing parts of our technical stack (see the `test/karma` directory), and to expedite the initial implementation phase of these tests. karma can be difficult to configure, and even more difficult to add new (i.e. different) testing paradigms and testing strategies to. given that these tests do not use browserstack and are a significant departure from the existing karma tests, it felt 'ok' to split these off into a separate set of tests (with their own configuration). in order to get tests up and running, a utilities file, `test/bundler/karma-stencil-utils.ts` has been created. this file is largely based off of `test/karma/test-app/util.ts`. parts of the existing utility file were not ported over if they were deemed unnecessary, and attempts were made to clean up the existing code to improve their readability. wire the bundler tests to github actions. these tests are kept in a new reusable workflow that can run in parallel with existing analysis, unit and e2e tests STENCIL-339: Integrate Bundler Functionality
👋 The core functionality in this PR has been made a part of the v2.16.0 release of Stencil. This functionality is gated under a new flag, I'm going to close this PR. Once again I wanted to thank @johnjenkins & @PrinceManfred for helping move this along. We couldn't have done it without y'all ❤️ |
Current behaviour
Stencil provides it's neat lazy-loader - include once then forget 🚀 - it's super useful.
The loader comes in 2 flavours. 1) is designed to be loaded via a <script> in a browser and that's that. Perfect for something like a CDN. 2) is designed to be bundled via a ... bundler:
Aside from copying static assets from
node_modules/@your-components/assets
topublic/assets
that's it.If you use webpack ^ that should all work nicely.
Try using that in parcel, vite, snopack, esbuild, rollup etc :(
The dynamic import expression that stencil's loader
loadModule
function ships with:import(`./${bundleId}.entry.js?${somethingElse}`).then(
Is webpack centric - the other bundlers don't know how to find the resources they need to bundle.
This PR / new behaviour
This small PR adds static imports to the stencil lazy loader's outputs that are not used directly in the browser (e.g. via CDN).
Because the import statements are static strings:
import(`./your-component.entry.js`).then(
All the other bundlers are happy.
How it works
The PR simply adds a comment 'hook' to the
client-load-module.ts
< where theloadModule
resides.Just before writing the core loader file to disk (which includes the
client-load-module.ts
module), it replaces the comment with a switch statement using all the potential 'entry modules' (component bundles that are lazy loaded) that are created by stencil to return static import statements.The static imports do not get added if the core loader is going to be used directly in the browser (e.g. via CDN).
The static imports will / should not apply when stencil is using HMR (the dynamic addition of the HMR ID will break static imports).
Testing
I have manually tested the PRs output against my live component library in:
If there's any more stuff that the current stencil loader is not working with - please leave a comment here and I'll check it out.
Fixes #2827
Fixes #2752