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

Support code injection in webpack 5 #1563

Merged
merged 7 commits into from
Mar 8, 2021

Conversation

Marc-Andre-Rivet
Copy link
Contributor

@Marc-Andre-Rivet Marc-Andre-Rivet commented Mar 6, 2021

The webpack-dash-dynamic-import plugin was written with Webpack 4.x in mind. With Webpack 5.x the API for plugins changed in a way that makes the existing code injection produce invalid JS bundles. This PR makes the injection work with both 4.x and 5.x.

Related to plotly/dash-table#875
Sanity check against Webpack 4.x project: https://app.circleci.com/pipelines/github/plotly/dash-core-components?branch=sanity-webpack-4and5

@alexcjohnson
Copy link
Collaborator

Nice find! Can you point to where this change is documented by Webpack? And I presume with this change we will support independently upgrading the renderer and individual component packages from 4 to 5?

@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019 Plotly
Copy link
Collaborator

Choose a reason for hiding this comment

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

FYI, as I wrote in https://github.com/plotly/dash-core/issues/324

I've seen some major packages like React drop the copyright year - that simplifies managing these and apparently doesn't have a strong downside, so I'd propose we do the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will bump to 2021 for now and until the discussion on this happens

@Marc-Andre-Rivet
Copy link
Contributor Author

Marc-Andre-Rivet commented Mar 7, 2021

Nice find! Can you point to where this change is documented by Webpack? And I presume with this change we will support independently upgrading the renderer and individual component packages from 4 to 5?

@alexcjohnson I can't find a reference to this in the plugins documentation and the fix is mostly through figuring out what it calls and what the expected behavior seems to be. It seems to boil down to major change in the internal implementation with Template.asString(<array>) being resolved in 4.x with https://github.com/webpack/webpack/blob/444e59f8a427f94f0064cae6765e5a3c4b78596d/lib/Template.js#L164 and being resolved with ${array} in 5.x with a third-party of their own making https://github.com/webpack/tapable/blob/master/lib/SyncWaterfallHook.js#L17

Their own usage changed accordingly between the versions, moving from arrays of values to string buffers.


Yes, the proposed code change should work fine with both Webpack 4 and 5 and allow individual projects to transition to the new version at their own pace.

@Marc-Andre-Rivet Marc-Andre-Rivet marked this pull request as ready for review March 7, 2021 15:05
@alexcjohnson
Copy link
Collaborator

OK so if in 4.x the array was eventually evaluated as source + '\n' + resolveImportSource(), and now in 5.x we can't do that but source + resolveImportSource() works, is there one of those two flavors that works in both 4 and 5, so we don't need to branch?

@Marc-Andre-Rivet
Copy link
Contributor Author

OK so if in 4.x the array was eventually evaluated as source + '\n' + resolveImportSource(), and now in 5.x we can't do that but source + resolveImportSource() works, is there one of those two flavors that works in both 4 and 5, so we don't need to branch?

Yes 😁

Copy link
Collaborator

@alexcjohnson alexcjohnson left a comment

Choose a reason for hiding this comment

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

Beautiful 💃
Just one little 🔪 comment

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.

2 participants