-
Notifications
You must be signed in to change notification settings - Fork 795
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(dist-custom-elements): automatically import and define depencies #3039
feat(dist-custom-elements): automatically import and define depencies #3039
Conversation
…omponent - will bootstrap components and any dependents
…ar as it's defining a complete, single component. init karma tests for `defineCustomElement`
…ing ts transforms before bundling.
…:johnjenkins/stencil into feat-custom-elements-import-dependencies
…:johnjenkins/stencil into johnjenkins-feat-custom-elements-import-dependencies
fixes the scenario where the element tag name does not match the class name after being transformed to PascalCase. Rely on the component class name
src/compiler/output-targets/dist-custom-elements/custom-elements-types.ts
Outdated
Show resolved
Hide resolved
src/compiler/transformers/component-native/add-define-custom-element-function.ts
Show resolved
Hide resolved
…ts-import-dependencies-ryan updates to `feat custom elements import dependencies`
Add '__PURE__' comment to component proxy function call for uglify.
OutputTargetDistCustomElements
…ts-import-dependencies-ryan-3 make auto definition optional
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Let's see what CI says
Hi @rwaskiewicz , Am using the React wrapper and this auto import and defining dependencies is not working with the React Wrapper from Stencil. Any workaround to handle it ? |
I used the v2.9.0-0 version to test this out. If I use the react output target , I see that all the components are getting bundled in the prod build instead of just the ones that are being used. If I use the dist/components instead of React, its working fine. Can you please let me know if this will be implemented with React wrapper as well ? |
@johnjenkins @rwaskiewicz Tree shaking is broken in Stencil React output target. ionic-team/stencil-ds-output-targets#198 Please find below my observation: I notice that, the tree shaking is not happening due to the below: The Spinner variable is getting reassigned and then assigned to the export of this module. This is causing the treeshaking to break. If I create a new variable and assign it instead of using the same Spinner variable and assign it to the export , tree shaking is working fine.
|
@splitinfinities The above PR is bloating the React js wrapper build(dist-custom-elements) and bundling all components . I have updated my observations above. Kindly review it. Thanks. |
Hey @arvindanta 👋 Thank you for your bug report. The team will investigate when they have a chance, but I can't promise a specific timeline. In the future, please know that the team is properly notified of comments on existing issues/PRs, there is no need to ping individual members of the team directly |
Hi Team, In the below dist custom elements component created, Tree shaking is not working in React output target. Reassigning MyComponent with the proxyCustomElement is breaking the tree shaking ability. Have attached the screenshot which uses the eslint-plugin-tree-shaking to check for issues with tree shaking. If I use different variable instead of reassigning to MyComponent, tree shaking is working fine with React Wrapper.
React wrapper code below:
|
Hi Team, This is one of the key features I was looking for regarding dist-custom-elements target. The only issue that this is having is now the React wrapper is not tree shakable.
The above function uses re assign MyComponent variable and this gets exported and is breaking the tree shakable ability (which is very imp with React wrapper(custom elements option)). Instead of reassigning to MyComponent, If I create a new variable and assign it as below
Tree shaking is working fine. Can someone point me to where to handle this change ? proxyCustomElement is a side effect function and webpack/rollup is tree shaking the modules that uses proxyelement and reassign to the variable. Please see the attached screenshot. I ran the coverage from chrome dev tools, the statement where proxyCustomElement call is getting reassigned to the class component (MyComponent/SecondComponent/ThirdCmp) is getting used while the rest of the code in those modules are unused and this is breaking the tree shaking ability and these modules are bundled together always |
Hey @arvindanta - can you please add this information to your existing issue in the stencil-ds-output-targets repo? That keeps information all in one place for the team to investigate this issue when they have the opportunity. |
Hi @rwaskiewicz Sure , I will add this info there. I feel the issue exists due to the mentioned change with the stencil core package and not very specific to the react output target. |
The little known
dist-custom-element
bundle has potential to be great for bundlers and tree-shaking - all components and dependencies are put into separate bundles. The disadvantage at the moment is that each and every component (and any dependency they may have) must be imported and defined individually.This PR adds a
defineCustomElement()
to each component bundle created withindist-custom-element
. Importing and calling it will not only define the component in question but any dependencies that component might have. e.g.Will define
<ion-button />
and also import and define<ion-ripple-effect />
.