Skip to content
This repository has been archived by the owner on Oct 10, 2022. It is now read-only.

Add blocks-frontend.js for blocks frontend scripts #135

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/cgb-scripts/config/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = {
dotenv: resolvePlugin( '.env' ),
pluginSrc: resolvePlugin( 'src' ), // Plugin src folder path.
pluginBlocksJs: resolvePlugin( 'src/blocks.js' ),
pluginBlocksFrontendJs: resolvePlugin( 'src/blocks-frontend.js' ),
yarnLockFile: resolvePlugin( 'yarn.lock' ),
pluginDist: resolvePlugin( '.' ), // We are in ./dist folder already so the path '.' resolves to ./dist/.
};
Expand All @@ -28,10 +29,11 @@ module.exports = {
dotenv: resolvePlugin( '.env' ),
pluginSrc: resolvePlugin( 'src' ),
pluginBlocksJs: resolvePlugin( 'src/blocks.js' ),
pluginBlocksFrontendJs: resolvePlugin( 'src/blocks-frontend.js' ),
pluginDist: resolvePlugin( '.' ), // We are in ./dist folder already so the path '.' resolves to ./dist/.
yarnLockFile: resolvePlugin( 'yarn.lock' ),
appPath: resolvePlugin( '.' ),
// These properties only exist before ejecting:
ownPath: resolveOwn( '.' ),
};
// @remove-on-eject-end
// @remove-on-eject-end
Copy link
Contributor

Choose a reason for hiding this comment

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

Please make sure that there is a blank line at the end of the file.

3 changes: 2 additions & 1 deletion packages/cgb-scripts/config/webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const extractConfig = {
module.exports = {
entry: {
'./dist/blocks.build': paths.pluginBlocksJs, // 'name' : 'path/file.ext'.
'./dist/frontend.blocks.build' : paths.pluginBlocksFrontendJs, // 'name' : 'path/file.ext'.
},
output: {
// Add /* filename */ comments to generated require()s in the output.
Expand Down Expand Up @@ -120,4 +121,4 @@ module.exports = {
// stats: 'errors-only',
// Add externals.
externals: externals,
};
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Another blank line issue.

3 changes: 2 additions & 1 deletion packages/cgb-scripts/config/webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ const extractConfig = {
module.exports = {
entry: {
'./dist/blocks.build': paths.pluginBlocksJs, // 'name' : 'path/file.ext'.
'./dist/frontend.blocks.build' : paths.pluginBlocksFrontendJs, // 'name' : 'path/file.ext'.
},
output: {
// Add /* filename */ comments to generated require()s in the output.
Expand Down Expand Up @@ -148,4 +149,4 @@ module.exports = {
// stats: 'errors-only',
// Add externals.
externals: externals,
};
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Another blank line issue.

1 change: 1 addition & 0 deletions packages/cgb-scripts/template/src/blocks-frontend.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Blocks frontend scripts
8 changes: 8 additions & 0 deletions packages/cgb-scripts/template/src/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ function <% blockNamePHPLower %>_cgb_block_assets() { // phpcs:ignore
array( 'wp-editor' ) // Dependency to include the CSS after it.
// filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.style.build.css' ) // Version: File modification time.
);
// Scripts.
wp_enqueue_script(
'<% blockNamePHPLower %>-cgb-blocks-frontend-js', // Handle.
plugins_url( '/dist/frontend.blocks.build.js', dirname( __FILE__ ) ), // frontend.blocks.build.js: We register the frontend scripts for block here. Built with Webpack.
array(), // Dependencies, defined above.
// filemtime( plugin_dir_path( __DIR__ ) . 'dist/frontend.blocks.build.js' ), // Version: File modification time.
true // Enqueue the script in the footer.
);
Copy link
Contributor

Choose a reason for hiding this comment

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

The version parameter to this function is commented out, which makes the last one its version parameter which is a mistake. Please correct it.

For more information, check this link: https://developer.wordpress.org/reference/functions/wp_enqueue_script/

}

// Hook: Frontend assets.
Expand Down