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

"wp-scripts build" doesn't copy reneder callback php file from src to build folder if "render" property set in block.json metadata #48696

Closed
realthemes opened this issue Mar 2, 2023 · 4 comments · Fixed by #48735
Assignees
Labels
Good First Issue An issue that's suitable for someone looking to contribute for the first time [Package] Scripts /packages/scripts [Type] Bug An existing feature does not function as intended

Comments

@realthemes
Copy link

Description

I'm developing my custom block plugin using create-block script, when the turn came to render callback file I set "render" metadata in block.json file like it say in documentation: "render": "file:./render.php", I also place file render.php in block folder but when I try to compile plugin whith npm run build command, the render.php file doesn't copied to /build/my-block/ folder, actually rest of plugin are compiling normally the only problem is copying. Currently I forced to use special command to force copy PHP files to build folder

Step-by-step reproduction instructions

  1. create block plugin with create-block
  2. set "render": "file:./render.php" metadata in block.json
  3. compile whith "npm run build"
  4. there no render.php file in build folder

Screenshots, screen recording, code snippet

No response

Environment info

Wordpress 6.1.1, built-in Gutenberg, custom theme
Google Chrome
Windows 11

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

@gziolo gziolo added [Package] Scripts /packages/scripts Needs Testing Needs further testing to be confirmed. labels Mar 3, 2023
@gziolo
Copy link
Member

gziolo commented Mar 3, 2023

@realthemes, thank you for the report. What version of @wordpress/scripts do you have installed? #43917 added support for automatic copying of the file defined in the render field of block.json. As far as I can tell, the version should be greater than 24.0.0.

I see that you noted that you use Windows, so maybe there is something wrong with how paths are handled. @t-hamano, would be so kind to verify that?

@realthemes
Copy link
Author

@gziolo here is the version - "@wordpress/scripts": "^25.4.0", sorry I was need to say that I make my plugin from single block to multiple block plugin, currently I have src folder and inside it nested my blocks folders, but I'm pretty sure that there no problem, beqause: 1. my plugin are compiling and all blocks are working, 2. If I use $ wp-scripts build --webpack-copy-php command then PHP file are copied correctly.

@gziolo
Copy link
Member

gziolo commented Mar 3, 2023

As long as the PHP file's path is relative to block.json, then it should pick it up. I assume it is because you didn't report issues with JS and CSS.

@t-hamano
Copy link
Contributor

t-hamano commented Mar 3, 2023

I didn't know until now that if the path to render.php is defined in block.json, it is automatically copied 😅 I mistakenly thought that we needed to specify the --webpack-copy-php option in order to copy the PHP file containing render.php.

Indeed, on Windows OS, it appears that the PHP file paths defined in block.json are not being copied. Below are the test results. I would like to explore the cause of the problem.

On Windows11

Build a single dynamic block

  • wp-scripts build: render.php file is NOT copied to the build directory
  • wp-scripts build --webpack-copy-php: render.php file and other PHP files are copied to the build directory

Build multiple blocks

  • wp-scripts build: render.php file is NOT copied to the build/{block} directory
  • wp-scripts build --webpack-copy-php: render.php file and other PHP files are copied to the build/{block} directory

On WSL2 (Ubuntu)

Build a single dynamic block

  • wp-scripts build: render.php file is copied to the build directory
  • wp-scripts build --webpack-copy-php: render.php file and other PHP files are copied to the build directory

Build multiple dynamic blocks

  • wp-scripts build: render.php file is copied to the build/{block} directory
  • wp-scripts build --webpack-copy-php: render.php file and other PHP files are copied to the build/{block} directory

@gziolo gziolo added [Type] Bug An existing feature does not function as intended Needs Dev Ready for, and needs developer efforts Good First Issue An issue that's suitable for someone looking to contribute for the first time and removed Needs Testing Needs further testing to be confirmed. labels Mar 3, 2023
@t-hamano t-hamano self-assigned this Mar 3, 2023
@priethor priethor removed the Needs Dev Ready for, and needs developer efforts label Jul 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good First Issue An issue that's suitable for someone looking to contribute for the first time [Package] Scripts /packages/scripts [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants