Add `CopyWebpackPlugin` to ensure `block.json` is copied to `build` (https://github.com/woocommerce/woocommerce-blocks/pull/5692)

* Add CopyWebpackPlugin and add block metadata to build

* Check build directory for block.json
This commit is contained in:
Thomas Roberts 2022-02-01 16:42:15 +00:00 committed by GitHub
parent 995d41e2a9
commit 5e32fb0576
4 changed files with 586 additions and 125 deletions

View File

@ -12,6 +12,7 @@ const TerserPlugin = require( 'terser-webpack-plugin' );
const CreateFileWebpack = require( 'create-file-webpack' );
const CircularDependencyPlugin = require( 'circular-dependency-plugin' );
const { BundleAnalyzerPlugin } = require( 'webpack-bundle-analyzer' );
const CopyWebpackPlugin = require( 'copy-webpack-plugin' );
/**
* Internal dependencies
@ -253,6 +254,14 @@ const getMainConfig = ( options = {} ) => {
new ProgressBarPlugin(
getProgressBarPluginConfig( 'Main', options.fileSuffix )
),
new CopyWebpackPlugin( {
patterns: [
{
from: './assets/js/blocks/checkout/block.json',
to: './checkout/block.json',
},
],
} ),
],
resolve: {
...resolve,

File diff suppressed because it is too large Load Diff

View File

@ -139,6 +139,7 @@
"chalk": "4.1.2",
"circular-dependency-plugin": "5.2.2",
"commander": "6.2.1",
"copy-webpack-plugin": "^6.4.1",
"core-js": "3.16.2",
"create-file-webpack": "1.0.2",
"cross-env": "6.0.3",

View File

@ -68,7 +68,7 @@ class Api {
* @return string|boolean False if metadata file is not found for the block.
*/
public function get_block_metadata_path( $block_name ) {
$path_to_metadata_from_plugin_root = $this->package->get_path( 'assets/js/blocks/' . $block_name . '/block.json' );
$path_to_metadata_from_plugin_root = $this->package->get_path( 'build/' . $block_name . '/block.json' );
if ( ! file_exists( $path_to_metadata_from_plugin_root ) ) {
return false;
}