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

Scripts: Convert file extension to js in block.json during build #41068

Merged
merged 3 commits into from
May 23, 2022
Merged
Changes from 1 commit
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
Next Next commit
convert file extension in block.json
  • Loading branch information
torounit committed May 14, 2022
commit d9a4a0177ce33a4adb284a13588fa25550693f48
18 changes: 18 additions & 0 deletions packages/scripts/config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,24 @@ const config = {
from: copyWebpackPatterns,
context: process.env.WP_SRC_DIRECTORY,
noErrorOnMissing: true,
transform( content, absoluteFrom ) {
if ( basename( absoluteFrom ) === 'block.json' ) {
const blockJson = JSON.parse( content.toString() );
[ 'viewScript', 'script', 'editorScript' ].forEach(
( key ) => {
if ( blockJson[ key ] ) {
blockJson[ key ] = blockJson[
key
].replace( /\.(j|t)sx?$/, '.js' );
}
}
);

return JSON.stringify( blockJson, null, 2 );
}

return content;
},
},
],
} ),
Expand Down