prismicio / prismic-next

Helpers to integrate Prismic into Next.js apps
https://prismic.io/docs/technologies/nextjs
Apache License 2.0
56 stars 7 forks source link

Updating to 0.1.2 adds the next/image chunk to my final bundle even if I don't use next/image #35

Closed gutierrez-cesar closed 2 years ago

gutierrez-cesar commented 2 years ago

Versions

Steps to reproduce

What is expected?

I would expect the next/image chunk to not be included in my project if I don't use the next Image component

github-actions[bot] commented 2 years ago

This issue has been labeled as a bug since it was created using the 🚨 Bug Report Template.

Hi there, thank you so much for the report!

Following our Maintenance Process, we will review your bug report and get back to you next Wednesday. To ensure a smooth review of your issue and avoid unnecessary delays, please make sure your issue includes the following:

If you have identified the cause of the bug described in your report and know how to fix it, you're more than welcome to open a pull request address it. Check out our quick start guide for a simple contribution process.

If you think your issue is a question (not a bug) and would like quicker support, please close this issue and forward it to an appropriate section on our community forum: https://community.prismic.io

- The Prismic Open-Source Team

angeloashmore commented 2 years ago

Thanks for the bug report, @gutierrez-cesar. The <PrismicNextImage> component was introduced in v0.1.3 which is why you are only seeing the added code after upgrading.

If you aren't using the component, it is supposed to be tree-shaken and excluded from the bundle. It likely is not being removed currently because the package does not mark itself as "side-effect free."

I will investigate. 🙂

angeloashmore commented 2 years ago

Hi @gutierrez-cesar, this should be fixed in v0.1.4.

The package needed to be built in a different way where it no longer bundles everything into one file. Since this package will always be used in Next.js, we can rely on Next.js to bundle. This lets Next.js's bundler omit code that is not used.

More details are available here: #36

You can update to the latest version with the following command:

npm install @prismicio/next@latest

If you are still noticing next/image in your builds, you may need to delete Next.js's build cache. You can clear it by deleting the .next directory that is created after building.

Thanks for the report! 🙂