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

POC: blocks bundling #32388

Closed
wants to merge 2 commits into from
Closed
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: 4 additions & 0 deletions projects/plugins/jetpack/changelog/poc-blocks-bundling
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: major
Type: enhancement

Update building blocks allow bundling and single builds
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"name": "jetpack/business-hours",
"title": "Business Hours",
"description": "Display opening hours for your business.",
"keywords": [ "opening hours", "closing time", "schedule", "working day" ],
"version": "12.5.0",
"textdomain": "jetpack",
"category": "grow"
}
203 changes: 107 additions & 96 deletions projects/plugins/jetpack/extensions/index.json
Original file line number Diff line number Diff line change
@@ -1,98 +1,109 @@
{
"production": [
"ai-assistant",
"ai-assistant-plugin",
"blogging-prompt",
"business-hours",
"button",
"calendly",
"cookie-consent",
"contact-form",
"contact-form/salesforce-lead-form",
"contact-info",
"donations",
"eventbrite",
"gathering-tweetstorms",
"gif",
"google-calendar",
"image-compare",
"instagram-gallery",
"likes",
"mailchimp",
"map",
"markdown",
"opentable",
"payments",
"pinterest",
"podcast-player",
"premium-content",
"publicize",
"rating-star",
"recurring-payments",
"related-posts",
"repeat-visitor",
"send-a-message",
"whatsapp-button",
"seo",
"sharing",
"shortlinks",
"simple-payments",
"slideshow",
"social-previews",
"story",
"subscriptions",
"tiled-gallery",
"tock",
"videopress",
"wordads",
"payments-intro",
"post-publish-qr-post-panel",
"payment-buttons",
"site-editor-snackbars",
"videopress/video",
"ai-assistant-support"
],
"beta": [
"ai-chat",
"amazon",
"author-recommendation",
"conversation",
"dialogue",
"google-docs-embed",
"launchpad-save-modal",
"post-publish-promote-post-panel",
"recipe",
"v6-video-frame-poster",
"videopress/video-chapters",
"paywall",
"ai-assistant-form-support"
],
"experimental": [ "ai-image", "ai-paragraph" ],
"no-post-editor": [
"ai-assistant",
"business-hours",
"button",
"calendly",
"contact-form",
"contact-info",
"donations",
"eventbrite",
"gif",
"google-calendar",
"instagram-gallery",
"mailchimp",
"map",
"markdown",
"opentable",
"pinterest",
"rating-star",
"related-posts",
"repeat-visitor",
"simple-payments",
"slideshow",
"tiled-gallery",
"tock",
"videopress",
"wordads"
]
"production": {
"prod": [
Copy link
Contributor

Choose a reason for hiding this comment

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

If we decide to gradually "unbundle" blocks, modifying the production/beta/etc. arrays might make it harder to keep both approaches simultaneously (i.e. both the main chunk of assets, and smaller custom bundles).

"ai-assistant",
"ai-assistant-plugin",
"blogging-prompt",
"button",
"calendly",
"cookie-consent",
"contact-form",
"contact-form/salesforce-lead-form",
"contact-info",
"donations",
"eventbrite",
"gathering-tweetstorms",
"gif",
"google-calendar",
"image-compare",
"instagram-gallery",
"likes",
"mailchimp",
"map",
"markdown",
"opentable",
"payments",
"pinterest",
"podcast-player",
"premium-content",
"publicize",
"rating-star",
"recurring-payments",
"related-posts",
"repeat-visitor",
"send-a-message",
"whatsapp-button",
"seo",
"sharing",
"shortlinks",
"simple-payments",
"slideshow",
"social-previews",
"story",
"subscriptions",
"tiled-gallery",
"tock",
"videopress",
"wordads",
"payments-intro",
"post-publish-qr-post-panel",
"payment-buttons",
"site-editor-snackbars",
"videopress/video",
"ai-assistant-support"
],
"business-hours" : [ "business-hours" ]
},
"beta": {
"bet": [
"ai-chat",
"amazon",
"author-recommendation",
"conversation",
"dialogue",
"google-docs-embed",
"launchpad-save-modal",
"post-publish-promote-post-panel",
"recipe",
"v6-video-frame-poster",
"videopress/video-chapters",
"paywall",
"ai-assistant-form-support"
]
},
"experimental": {
"exp": [
"ai-image",
"ai-paragraph"
]
},
"noPostEditor": {
"np": [
"ai-assistant",
"business-hours",
"button",
"calendly",
"contact-form",
"contact-info",
"donations",
"eventbrite",
"gif",
"google-calendar",
"instagram-gallery",
"mailchimp",
"map",
"markdown",
"opentable",
"pinterest",
"rating-star",
"related-posts",
"repeat-visitor",
"simple-payments",
"slideshow",
"tiled-gallery",
"tock",
"videopress",
"wordads"
]
}
}
90 changes: 30 additions & 60 deletions projects/plugins/jetpack/tools/webpack.config.extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,64 +38,28 @@ function presetProductionExtensions( type, inputDir, presetBlocks ) {

const presetPath = path.join( __dirname, '../extensions', 'index.json' );
const presetIndex = require( presetPath );
const presetProductionBlocks = presetIndex.production || [];
const presetNoPostEditorBlocks = presetIndex[ 'no-post-editor' ] || [];

const presetExperimentalBlocks = [
...presetProductionBlocks,
...( presetIndex.experimental || [] ),
];
// Beta Blocks include all blocks: beta, experimental, and production blocks.
const presetBetaBlocks = [ ...presetExperimentalBlocks, ...( presetIndex.beta || [] ) ];

// Helps split up each block into its own folder view script
const viewBlocksScripts = presetBetaBlocks.reduce( ( viewBlocks, block ) => {
const viewScriptPath = path.join( __dirname, '../extensions/blocks', block, 'view.js' );
if ( fs.existsSync( viewScriptPath ) ) {
viewBlocks[ block + '/view' ] = [ viewSetup, ...[ viewScriptPath ] ];
}
return viewBlocks;
const editorProductionScripts = Object.keys( presetIndex ).reduce( ( acc, envr ) => {
Object.keys( presetIndex[ envr ] ).forEach( bundleName => {
const bundle = presetIndex[ envr ][ bundleName ];
const blockPath = path.join( __dirname, '../extensions' );
acc[ `${ bundleName }/editor` ] = [
editorSetup,
...presetProductionExtensions( 'editor', blockPath, bundle ),
];
for ( const blockName of bundle ) {
if ( acc[ blockName + '/view' ] ) {
continue;
}
const viewScriptPath = path.join( __dirname, '../extensions/blocks', blockName, 'view.js' );
if ( fs.existsSync( viewScriptPath ) ) {
acc[ blockName + '/view' ] = [ viewSetup, ...[ viewScriptPath ] ];
}
}
} );
return acc;
}, {} );

// Combines all the different production blocks into one editor.js script
const editorScript = [
editorSetup,
...presetProductionExtensions(
'editor',
path.join( __dirname, '../extensions' ),
presetProductionBlocks
),
];

// Combines all the different Experimental blocks into one editor.js script
const editorExperimentalScript = [
editorSetup,
...presetProductionExtensions(
'editor',
path.join( __dirname, '../extensions' ),
presetExperimentalBlocks
),
];

// Combines all the different blocks into one editor-beta.js script
const editorBetaScript = [
editorSetup,
...presetProductionExtensions(
'editor',
path.join( __dirname, '../extensions' ),
presetBetaBlocks
),
];

const editorNoPostEditorScript = [
editorSetup,
...presetProductionExtensions(
'editor',
path.join( __dirname, '../extensions' ),
presetNoPostEditorBlocks
),
];

const sharedWebpackConfig = {
mode: jetpackWebpackConfig.mode,
devtool: jetpackWebpackConfig.devtool,
Expand Down Expand Up @@ -176,11 +140,8 @@ module.exports = [
{
...sharedWebpackConfig,
entry: {
editor: editorScript,
'editor-experimental': editorExperimentalScript,
'editor-beta': editorBetaScript,
'editor-no-post-editor': editorNoPostEditorScript,
...viewBlocksScripts,
...editorProductionScripts,
'editor-core': path.join( __dirname, '../extensions/editor.js' ),
},
plugins: [
...sharedWebpackConfig.plugins,
Expand All @@ -193,6 +154,15 @@ module.exports = [
],
} ),
new CopyBlockEditorAssetsPlugin(),
new CopyWebpackPlugin( {
patterns: [
{
from: '**/block.json',
to: '[path][name][ext]',
context: path.join( __dirname, '../extensions/blocks' ),
},
],
} ),
],
},
{
Expand Down