Skip to content

Commit

Permalink
Copy block.json files over to root blocks folder
Browse files Browse the repository at this point in the history
For the block registration, we need access to the `block.json` file. Therefore, we need to ensure the path is the same in development and production (zip).
This commit solves that by effectively making the root blocks folder the "dist" or "build" folder for our block.json files.

When bundling, any `block.json` files found (within our entry scripts) are copied over to the root blocks folder.
Keeping the folder structure in place from `packages/js/src` onwards.

When creating an artifact, the blocks root folder is copied to the artifact folder.
Note: the webpack copy currently has no support for any CSS or JS alongside, but the artifact copy ignore extensions already.
  • Loading branch information
igorschoester authored and enricobattocchi committed Apr 23, 2024
1 parent 01f20eb commit 123ecf3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ test.sh
/js/dist/*
/css/dist/*
/packages/*/dist
/blocks/**
yarn-error.log
coverage
dependencies.json
Expand All @@ -108,4 +109,4 @@ dependencies.md
############
/.tmp

.cache/phpunit/cache/
.cache/phpunit/cache/
1 change: 1 addition & 0 deletions config/grunt/task-config/copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module.exports = {
"packages/js/images/**",
"inc/**",
"<%= paths.jsDist %>/**/*.js",
"blocks/**",
"languages/**",
"src/**",
"lib/**",
Expand Down
3 changes: 2 additions & 1 deletion config/webpack/webpack.config.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const { yoastExternals } = require( "./externals" );

let analyzerPort = 8888;

module.exports = function( { entry, output, combinedOutputFile, cssExtractFileName } ) {
module.exports = function( { entry, output, combinedOutputFile, cssExtractFileName, plugins = [] } ) {
return {
...defaultConfig,
optimization: {
Expand Down Expand Up @@ -95,6 +95,7 @@ module.exports = function( { entry, output, combinedOutputFile, cssExtractFileNa
// Copied from WP config: Inject the `SCRIPT_DEBUG` global, used for development features flagging.
SCRIPT_DEBUG: process.env.NODE_ENV !== "production",
} ),
...plugins,
].filter( Boolean ),
};
};
14 changes: 13 additions & 1 deletion config/webpack/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// External dependencies
const CopyWebpackPlugin = require( "copy-webpack-plugin" );
const { readdirSync } = require( "fs" );
const { join } = require( "path" );
const { join, resolve } = require( "path" );

// Variables
const root = join( __dirname, "../../" );
Expand Down Expand Up @@ -29,6 +30,17 @@ module.exports = [
},
combinedOutputFile: root + "src/generated/assets/plugin.php",
cssExtractFileName: "../../../css/dist/plugin-" + pluginVersionSlug + ".css",
plugins: [
new CopyWebpackPlugin( {
patterns: [
{
from: "**/block.json",
context: "packages/js/src",
to: resolve( "blocks" ),
},
],
} ),
],
}
),
baseConfig(
Expand Down

0 comments on commit 123ecf3

Please sign in to comment.