Code Monkey home page Code Monkey logo

Comments (4)

borisdiakur avatar borisdiakur commented on June 21, 2024 1

Hey @vvision 👋

Good news. It's not a bug. It's a feature.

It's not a bug, it's a feature!

First of all, Liquid should not be external: You want to include the component code in your bundle. => You should remove the external config option.

Now, with Liquid 4.6.0, lots of chunks, which are actually never loaded in the browser, end up in your dist folder. So, why is the tree-shaking not working? Well, it kind of is working, because Rollup figures that all chunks are needed eventually, and the chunks are loaded in the browser only when needed. So why does Rollup "assume" that all chunks are needed? This is related to the includeDefineCustomElements option of the react output target!

Since liquid v4.6.0 the includeDefineCustomElements option set to true. With the includeDefineCustomElements option set to true, you don't need to define the custom elements from liquid react yourself. The custom elements get registered with the Custom Elements Registry as soon as imported. We didn't see this as a breaking change, because calling the defineCustomElements helper method manually would not break anything, even if the elements were already defined.

However things get tricky, when bundling liquid components into another library:
With the includeDefineCustomElements option set to true, the react.js and vue.js files within liquid import the defineCustomElements helper and execute it. The defineCustomElements helper imports the bootstrapLazy helper which in turn includes dynamic import statements for all components. Now, a bundler cannot know, which component will be lazy loaded eventually, so it includes all components as chunks into the bundle. The app that consumes the library can load only what's needed, but the bundle is still unnecessary big, including all Liquid components, even if not used.

In order to solve this issue, we have added additional entry points to the output targets, which do not include the defineCustomElements helper utility. This allows you to manually register custom elements on a as-needed basis, and fixes issues with the bundling, because dynamic imports are not used in the code. How to use this new feature is documented under Manually defining custom elements.

TLDR:
import { LdButton, LdTypo } from '@emdgroup-liquid/liquid/dist/react-define-excluded'

Please note that the feature is available in the newest version of Liquid. There is a major version bump which you need to take care of, but it should be really straight forward, as the breaking change in v5 is only relevant for a very special use case of liquid.

Let me know if something is still not working for you. 🤓

from liquid.

borisdiakur avatar borisdiakur commented on June 21, 2024 1

🎉 This issue has been resolved in version 5.5.0 🎉

The release is available on:

📦🚀

from liquid.

vvision avatar vvision commented on June 21, 2024 1

Hey @borisdiakur 👋,

Thanks for all the explanations and the great work.
I've implemented the proposed solution and it works flawlessly !

Many thanks from our team.

from liquid.

borisdiakur avatar borisdiakur commented on June 21, 2024

@vvision Thanks for submitting this issue and putting so much effort in it. 🙏
I'm looking into it. It's a tricky one. 😬

from liquid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.