decap-cms icon indicating copy to clipboard operation
decap-cms copied to clipboard

Move polyfill resolution from webpack to package.json

Open fgnass opened this issue 10 months ago • 1 comments

Summary

This PR simplifies the setup for users consuming decap-cms-app directly by addressing Node.js built-in dependencies in a different way.

Problem:

  1. Many decap packages depend on Node.js built-ins (particularly path)
  2. Currently, these are only polyfilled via webpack configuration in the pre-built bundle
  3. Users consuming decap-cms-app directly must manually configure their build tools to provide these polyfills

Solution:

  1. Leverage the standard browser field in package.json to specify browser-compatible alternatives
    • This is widely supported by modern build tools (webpack, Vite, Rollup, etc.)
    • Eliminates need for manual polyfill configuration
  2. Reduce polyfill requirements by:
    • Using @iarna/toml/parse-string instead of full @iarna/toml to eliminate stream dependency
    • Updating minimatch to a more recent version which removes Node.js built-in dependencies

These changes make the library more portable and easier to integrate across different build environments.

Test plan

  • Build succeeds ✅
  • tests:all pass ✅
  • demo runs ✅

Checklist

Please add a x inside each checkbox:

A picture of a cute animal (not mandatory but encouraged)

🐣

fgnass avatar Feb 06 '25 13:02 fgnass

Update: I noticed that @iarna/tomlrequires a global polyfill and gray-matter requires Buffer at runtime. To fix this, I added lib/polyfill.js which is now the first thing that gets imported by bootstrap.js.

With this change in place, we could also remove the ProvidePlugin from the webpack config, but I chose to keep it in place for now to keep the change as minimal as possible.

fgnass avatar Feb 22 '25 08:02 fgnass

@fgnass, I agree with the ProvidePlugin removal as part of this PR. If we don't do it now, we will probably forget about it.

martinjagodic avatar Jun 26 '25 12:06 martinjagodic

I take it back. This PR solves #7521, so I would merge as is.

martinjagodic avatar Jun 27 '25 08:06 martinjagodic