Skip to content
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

Tree Shakeable esm build (+demo) #607

Merged
merged 3 commits into from Mar 28, 2024
Merged

Tree Shakeable esm build (+demo) #607

merged 3 commits into from Mar 28, 2024

Conversation

erikyo
Copy link
Collaborator

@erikyo erikyo commented Mar 28, 2024

What?

I've made some updates and improvements to the Vanilla LazyLoad build steps, in order to take advantage of all the possibilities offered by ES Module.

😉 Why?

To use the ES6 module (ESM) build as tree shakeable instead of a single file has several advantages:

  • Tree shaking is a technique used by bundlers like Rollup and Webpack to remove dead code or unused exports from the final bundle. When using an ESM build, the bundler can analyze the module's import and export statements more effectively, allowing for more precise tree shaking. This results in a smaller bundle size because only the code that is actually used in the application gets bundled.
  • Future Compatibility: ESM is the standard module format in modern JavaScript, and it's increasingly being adopted by libraries and frameworks. By using ESM builds, the project remains aligned with current JavaScript standards, ensuring better compatibility with future tooling and environments.

Here's a breakdown of what's been done:

Package json

Dependency Updates:

  • Updated various dependencies to their latest versions for better compatibility and security:

Rollup Setup Enhancement:

  • Refactored the Rollup setup to improve performance and maintainability.
  • Switched to ES6 module format for better compatibility and readability.
  • Enabled tree shaking and module preservation to optimize the build output.

Demo Addition:
Added a demo to showcase the functionality of the esm module.

Warns
The compiled files were not included in this PR to avoid clutter. Anyhow if requested, they can be added before merging the PR

Recap
These changes aim to ensure the Vanilla LazyLoad module stays up-to-date and continues to deliver a seamless experience for users. I've tested these modifications extensively to ensure they work as intended.

Please review the changes at your earliest convenience, and let me know if there are any further adjustments or additions needed.

Thanks for considering these updates!

@verlok verlok merged commit 49bff68 into verlok:master Mar 28, 2024
@erikyo erikyo deleted the esm branch March 28, 2024 19:38
"rollup": "^2.44.0",
"rollup-plugin-terser": "^7.0.2"
"@babel/core": "^7.24.3",
"@babel/plugin-transform-object-assign": "^7.24.1",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated, but this is probably not needed anymore (nor in babelrc)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've kept the that module since it appears to be utilized here:

babel({
babelHelpers: "bundled",
exclude: "node_modules/**"
})

It pertained to the "non" ESM module. I'm uncertain why it was present, whether it was for the utilization of the "plugin-transform-object-assign" plugin or for transpiling to a JavaScript language target version. Thus, I chose to retain it, but yes probably isn't required anymore.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, I just noticed it and thought I'd mention it in case someone wants to drop it later :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants