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

How Webpack and WordPress packages interact #79

Closed
bph opened this issue Feb 14, 2023 Discussed in #15 · 9 comments
Closed

How Webpack and WordPress packages interact #79

bph opened this issue Feb 14, 2023 Discussed in #15 · 9 comments
Assignees

Comments

@bph
Copy link
Collaborator

bph commented Feb 14, 2023

Discussed in #15

Originally posted by bph October 13, 2022
During the discussion Issue #8
@andrewlimaza commented

"The main hurdle is the tooling around here and not fully understanding webpack. We tweak the wordpress/scripts webpack to adjust the entry and output points to fit our file structure. What we need is to output to assets/js and entry point would be /blocks (with various subfolders).

Right now, it nukes everything in the assets/js whenever you use wp-scripts start or build. Not sure if this is a NPM version thing or if there's a setting we can use to keep pre-existing files (other .js files for plugin frontend/admin etc) and just rebuild the files we need (i.e. blocks.build.js).

Also a standardized file structure for blocks (within a plugin) would help us, this is something we're working on for our own team (not paving the way for WP) but with the ever evolving tools and understanding of blocks we need to neaten this up internally as we built blocks before wp-scripts was a thing or we just didn't know about it (I can't remember 5 years ago what was our thought approach). We have moved over to wp-scripts ever since which made things easier but still gets confusing to troubleshoot this when things don't work. Our goal now is to to move to a set file structure and webpack config in upcoming plugins that already have shortcodes and other /js files. We have made some workarounds but I don't feel that these are ideal."

There definitely a need to elaborate on the interaction between Webpack and WordPress scripts, to guide developers through the build process and make adopting some tools easier. What do you think should be covered in a first blog post about it?

@bph
Copy link
Collaborator Author

bph commented Feb 14, 2023

@ryanwelcher post a preliminary outline in this comment

I'd probably start with the relationship between the @wordpress/scripts package and the [DependencyExtractionPlugin](https://www.npmjs.com/package/@wordpress/dependency-extraction-webpack-plugin) to clarify:

Why developers can use the import syntax without needing to npm install any @wordpress/* packages when using the build processes provided by the @wordpress/scripts package.
Where the index.asset.php file comes from and what purpose it serves.
Then I'd most likely look at the @wordpress/scripts package, explain how it works out of the box and then look at some examples on how to extend/modify the webpack configuration to :

  • Add additional entry points
  • Modify the entry point where block are stored
  • Look at custom output paths
  • Also a standardized file structure for blocks (within a plugin) would help us

This could be addressed by talking about the @wordpress/create-block package as it provides a suggested structure, but would that be better suited as a separate article where we could also talk about custom templates?

@bph bph moved this from Topic needs approval to To-do in Developer Blog Content Board Mar 2, 2023
@bph bph added the flow: approved can move forward label Mar 2, 2023
@bph bph moved this from To-do to In Progress in Developer Blog Content Board Apr 4, 2023
@ryanwelcher
Copy link

@ryanwelcher ryanwelcher moved this from In Progress to Needs 1st review in Developer Blog Content Board Apr 14, 2023
@marybaum
Copy link
Member

Got a couple of things on my plate today. Can I look early-ish tomorrow?

@ryanwelcher
Copy link

This is ready for 2nd review - https://developer.wordpress.org/news/?p=1226&preview=1&_ppp=305a6df22c

@ryanwelcher ryanwelcher moved this from Needs 1st review to Needs 2nd review in Developer Blog Content Board Apr 21, 2023
@ryanwelcher
Copy link

@marybaum do you think you'll have some time to review the post today?

@marybaum
Copy link
Member

marybaum commented Apr 24, 2023 via email

@marybaum
Copy link
Member

Done!

@bph
Copy link
Collaborator Author

bph commented Apr 25, 2023

@ryanwelcher seems you are ready to publish! ✅

Here is the pre-publish checklist

  • Post Title in Sentence case
  • Are Category or Categories selected?
  • Are Tags identifies?
  • Is there an explicit Excerpt?
  • Props added?
  • 🙌 Publish! 📗
  • add Props for reviews to #props channel in WP Slack
  • Share post on Twitter, or LInkedIN or other social networks.

@bph
Copy link
Collaborator Author

bph commented Apr 26, 2023

Post was published by @ryanwelcher How webpack and WordPress packages interact

@bph bph closed this as completed Apr 26, 2023
@github-project-automation github-project-automation bot moved this from Needs 2nd review to Ready to publish in Developer Blog Content Board Apr 26, 2023
@bph bph moved this from Ready to publish to Published (Done) in Developer Blog Content Board Apr 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Published (Done)
Development

No branches or pull requests

3 participants