You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm developing a custom Gutenberg blocks plugin and have integrated an image optimization process into my workflow. I'm using sharp in a custom Node.js script to generate optimized WebP versions of images for each block and copying them to the appropriate directories under the build folder. Each block follows a structure like:
build/{block-name}/assets/images
The issue I’m facing is that the build process using wp-scripts removes these optimized images from the build folder. Every time I run the build, Webpack cleans the build directory before rebuilding, which results in all optimized images being deleted.
I've tried several approaches to configure Webpack to exclude these images from being removed, including:
I attempted to modify the Webpack configuration by adding CleanWebpackPlugin to prevent the removal of the assets/images directories. However, I wasn’t successful in preserving the files.
I used the @wordpress/scripts setup and added custom configurations by extending Webpack’s behavior. Even with adjustments to exclude certain patterns (!assets/images/**), it seems the configuration is overridden or not respected during the clean step.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm developing a custom Gutenberg blocks plugin and have integrated an image optimization process into my workflow. I'm using
sharp
in a custom Node.js script to generate optimized WebP versions of images for each block and copying them to the appropriate directories under the build folder. Each block follows a structure like:build/{block-name}/assets/images
The issue I’m facing is that the build process using
wp-scripts
removes these optimized images from the build folder. Every time I run the build, Webpack cleans the build directory before rebuilding, which results in all optimized images being deleted.I've tried several approaches to configure Webpack to exclude these images from being removed, including:
I attempted to modify the Webpack configuration by adding
CleanWebpackPlugin
to prevent the removal of theassets/images
directories. However, I wasn’t successful in preserving the files.I used the
@wordpress/scripts
setup and added custom configurations by extending Webpack’s behavior. Even with adjustments to exclude certain patterns (!assets/images/**), it seems the configuration is overridden or not respected during the clean step.Here's my
package.json
:And here’s the custom Webpack configuration I’ve tried:
Despite logging the configuration to confirm it's being loaded, the optimized images are still removed during the build process.
Is there a recommended way to configure the
wp-scripts
build process to exclude specific directories from being cleaned?Or, is there an alternative approach I could take to integrate the image optimization process into the build without it being overwritten?
Any advice or suggestions would be greatly appreciated! 🙏🏼
Beta Was this translation helpful? Give feedback.
All reactions