Skip to content

Commit

Permalink
Add JS entry point for block editor.
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitrox committed Jan 7, 2025
1 parent e3b6107 commit f1384a5
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 3 deletions.
17 changes: 17 additions & 0 deletions assets/js/googlesitekit-reader-revenue-manager-block-editor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Reader Revenue Manager module's block editor entrypoint.
*
* Site Kit by Google, Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
25 changes: 24 additions & 1 deletion includes/Modules/Reader_Revenue_Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace Google\Site_Kit\Modules;

use Exception;
use Google\Site_Kit\Core\Assets\Asset;
use Google\Site_Kit\Core\Assets\Script;
use Google\Site_Kit\Core\Authentication\Clients\Google_Site_Kit_Client;
use Google\Site_Kit\Core\Modules\Module;
Expand All @@ -32,6 +33,7 @@
use Google\Site_Kit\Core\Site_Health\Debug_Data;
use Google\Site_Kit\Core\Tags\Guards\Tag_Environment_Type_Guard;
use Google\Site_Kit\Core\Tags\Guards\Tag_Verify_Guard;
use Google\Site_Kit\Core\Util\Feature_Flags;
use Google\Site_Kit\Core\Util\URL;
use Google\Site_Kit\Modules\Reader_Revenue_Manager\Settings;
use Google\Site_Kit\Modules\Reader_Revenue_Manager\Synchronize_OnboardingState;
Expand Down Expand Up @@ -383,7 +385,7 @@ function ( $url ) {
protected function setup_assets() {
$base_url = $this->context->url( 'dist/assets/' );

return array(
$assets = array(
new Script(
'googlesitekit-modules-reader-revenue-manager',
array(
Expand All @@ -400,6 +402,27 @@ protected function setup_assets() {
)
),
);

if ( Feature_Flags::enabled( 'rrmModuleV2' ) ) {
$assets[] = new Script(
'googlesitekit-reader-revenue-manager-block-editor.js',
array(
'src' => $base_url . 'js/googlesitekit-reader-revenue-manager-block-editor.js',
'dependencies' => array(
'googlesitekit-data',
'googlesitekit-i18n',
'googlesitekit-modules',
'wp-components',
'wp-editor',
'wp-element',
'wp-plugins',
),
'load_contexts' => array( Asset::CONTEXT_ADMIN_POST_EDITOR ),
)
);
}

return $assets;
}

/**
Expand Down
4 changes: 4 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
const { createRules } = require( './webpack/common' );
const adminCssConfig = require( './webpack/adminCss.config' );
const basicModulesConfig = require( './webpack/basicModules.config' );
const blockEditorConfig = require( './webpack/blockEditor.config' );
const frontendModules = require( './webpack/frontendModules.config' );
const modulesConfig = require( './webpack/modules.config' );
const testBundleConfig = require( './webpack/testBundle.config' );
Expand All @@ -45,6 +46,9 @@ function* webpackConfig( env, argv ) {
// Build modules that will be used on the frontend, that require wider browser support.
yield frontendModules( mode );

// Build the block editor js.
yield blockEditorConfig( mode );

// Build the main plugin admin css.
yield adminCssConfig( mode );
}
Expand Down
89 changes: 89 additions & 0 deletions webpack/blockEditor.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/**
* Block editor config webpack partial.
*
* Site Kit by Google, Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* External dependencies
*/
const CircularDependencyPlugin = require( 'circular-dependency-plugin' );
const ESLintPlugin = require( 'eslint-webpack-plugin' );
const ManifestPlugin = require( 'webpack-manifest-plugin' );
const WebpackBar = require( 'webpackbar' );

/**
* Internal dependencies
*/
const {
rootDir,
manifestArgs,
resolve,
gutenbergExternals,
createRules,
createMinimizerRules,
} = require( './common' );

module.exports = ( mode ) => ( {
entry: {
'googlesitekit-reader-revenue-manager-block-editor':
'./assets/js/googlesitekit-reader-revenue-manager-block-editor.js',
},
externals: gutenbergExternals,
output: {
filename:
mode === 'production' ? '[name]-[contenthash].js' : '[name].js',
path: rootDir + '/dist/assets/js',
publicPath: '',
// If multiple webpack runtimes (from different compilations) are used on the
// same webpage, there is a risk of conflicts of on-demand chunks in the global
// namespace.
// See: https://webpack.js.org/configuration/output/#outputjsonpfunction.
jsonpFunction: '__googlesitekit_block_editor_webpackJsonp',
},
performance: {
maxEntrypointSize: 175000,
},
module: {
rules: createRules( mode ),
},
plugins: [
new WebpackBar( {
name: 'Block Editor Entry Points',
color: '#deff13',
} ),
new CircularDependencyPlugin( {
exclude: /node_modules/,
failOnError: true,
allowAsyncCycles: false,
cwd: process.cwd(),
} ),
new ManifestPlugin( {
...manifestArgs( mode ),
filter( file ) {
return ( file.name || '' ).match( /\.js$/ );
},
} ),
new ESLintPlugin( {
emitError: true,
emitWarning: true,
failOnError: true,
} ),
],
optimization: {
minimizer: createMinimizerRules( mode ),
},
resolve,
} );
4 changes: 2 additions & 2 deletions webpack/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,11 @@ const gutenbergExternals = {
'@wordpress/i18n': [ 'googlesitekit', 'i18n' ],
};

exports.gutenbergExternals = gutenbergExternals;

corePackages.forEach( ( name ) => {
gutenbergExternals[ `@wordpress-core/${ name }` ] = [
'wp',
name.replace( /-([a-z])/g, ( match, letter ) => letter.toUpperCase() ),
];
} );

exports.gutenbergExternals = gutenbergExternals;

0 comments on commit f1384a5

Please sign in to comment.