Skip to content

Compile blocks under assets/build/blocks/#707

Open
pratik-londhe4 wants to merge 3 commits into
theme-elementary-v2from
feat/fix-build-blocks-css
Open

Compile blocks under assets/build/blocks/#707
pratik-londhe4 wants to merge 3 commits into
theme-elementary-v2from
feat/fix-build-blocks-css

Conversation

@pratik-londhe4

Copy link
Copy Markdown

Description

Block source files under src/blocks/ weren't being compiled by the theme's build. This PR adds a dedicated build step that compiles them to assets/build/blocks/, matching the pattern in features-plugin-skeleton.

Technical Details

The theme's custom webpack.config.js only declares entries for src/css/ and src/js/{frontend,admin,editor}/src/blocks/ was not in any entry list. The reason blocks appeared to be built was that wp-scripts' inherited CopyPlugin was silently copying block.json / render.php from src/blocks/ into assets/build/js/blocks/. No edit.js / view.js / index.js were being compiled, and no *.asset.php was being emitted alongside.

The fix mirrors the plugin skeleton:

Checklist

  • Add build:blocks npm script using wp-scripts' default config + --webpack-src-dir / --output-path
  • Restructure build:dev and build:prod to fan out to *:js + :blocks
  • Filter CopyPlugin out of inherited webpack plugins to stop duplicating block files into assets/build/js/blocks/
  • Verify compiled output under assets/build/blocks/example-block-*/
  • Verify assets/build/js/blocks/ no longer exists after a clean build

Screenshots

To-do

Fixes/Covers issue

Fixes #

Copilot AI review requested due to automatic review settings June 4, 2026 11:02

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the theme’s build pipeline so block sources under src/blocks/ are compiled into assets/build/blocks/, and prevents @wordpress/scripts’ inherited copy behavior from duplicating block files into the JS build output.

Changes:

  • Add a dedicated build:blocks script and fan build:dev / build:prod out into *:js + build:blocks.
  • Filter out the inherited CopyPlugin from the theme’s extended webpack config to avoid copying block files into assets/build/js/blocks/.
  • Update the npm lockfile to reflect dependency graph changes.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.

File Description
webpack.config.js Filters inherited webpack plugins to remove the wp-scripts CopyPlugin and avoid redundant block file copying into the JS output dir.
package.json Introduces build:blocks and restructures build scripts to run both JS and block builds.
package-lock.json Updates lockfile dependency metadata (currently inconsistent with package.json).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread package.json
Comment thread package.json
"build:dev:js": "wp-scripts start --no-watch --experimental-modules",
"build:prod": "npm-run-all build:prod:js build:blocks",
"build:prod:js": "wp-scripts build --experimental-modules",
"build:blocks": "wp-scripts build --experimental-modules --config ./node_modules/@wordpress/scripts/config/webpack.config.js --webpack-src-dir=./src/blocks/ --output-path=./assets/build/blocks/",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

build:blocks runs wp-scripts build (production mode) and is reused by both build:dev and build:prod. So a build:dev produces minified, source-map-less block output while the rest of the dev build is in development mode. Consider a dev block variant (wp-scripts start --no-watch …) so dev parity holds.

Also note npm start (--hot) doesn't call this at all, so blocks aren't compiled during HMR — and CleanBuildPlugin wipes assets/build on start, so there's no stale copy either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants