Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Commit 4803c71

Browse files
committed
Create wc-all-block-styles chunk with all the styles for classic themes (#10543)
1 parent 16270be commit 4803c71

File tree

5 files changed

+80
-6
lines changed

5 files changed

+80
-6
lines changed

bin/webpack-configs.js

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ const getSiteEditorConfig = ( options = {} ) => {
733733
* @param {Object} options Build options.
734734
*/
735735
const getStylingConfig = ( options = {} ) => {
736-
let { fileSuffix } = options;
736+
let { fileSuffix, isClassicThemeConfig } = options;
737737
const { alias, resolvePlugins = [] } = options;
738738
fileSuffix = fileSuffix ? `-${ fileSuffix }` : '';
739739
const resolve = alias
@@ -775,11 +775,58 @@ const getStylingConfig = ( options = {} ) => {
775775
chunks: 'all',
776776
priority: 10,
777777
},
778+
...( isClassicThemeConfig && {
779+
vendorsStyle: {
780+
test: /[\/\\]node_modules[\/\\].*?style\.s?css$/,
781+
name: 'wc-blocks-vendors-style',
782+
chunks: 'all',
783+
priority: 7,
784+
},
785+
blocksStyle: {
786+
// Capture all stylesheets with name `style` or name that starts with underscore (abstracts).
787+
test: /(style|_.*)\.scss$/,
788+
name: 'wc-all-blocks-style',
789+
chunks: 'all',
790+
priority: 5,
791+
},
792+
} ),
778793
},
779794
},
780795
},
781796
module: {
782797
rules: [
798+
{
799+
test: /[\/\\]node_modules[\/\\].*?style\.s?css$/,
800+
use: [
801+
MiniCssExtractPlugin.loader,
802+
{ loader: 'css-loader', options: { importLoaders: 1 } },
803+
'postcss-loader',
804+
{
805+
loader: 'sass-loader',
806+
options: {
807+
sassOptions: {
808+
includePaths: [ 'node_modules' ],
809+
},
810+
additionalData: ( content ) => {
811+
const styleImports = [
812+
'colors',
813+
'breakpoints',
814+
'variables',
815+
'mixins',
816+
'animations',
817+
'z-index',
818+
]
819+
.map(
820+
( imported ) =>
821+
`@import "~@wordpress/base-styles/${ imported }";`
822+
)
823+
.join( ' ' );
824+
return styleImports + content;
825+
},
826+
},
827+
},
828+
],
829+
},
783830
{
784831
test: /\.(j|t)sx?$/,
785832
use: {
@@ -800,6 +847,7 @@ const getStylingConfig = ( options = {} ) => {
800847
},
801848
{
802849
test: /\.s?css$/,
850+
exclude: /node_modules/,
803851
use: [
804852
MiniCssExtractPlugin.loader,
805853
'css-loader',

bin/webpack-entries.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,16 @@ const getBlockEntries = ( relativePath ) => {
114114

115115
const entries = {
116116
styling: {
117+
// @wordpress/components styles
118+
'custom-select-control-style':
119+
'./node_modules/wordpress-components/src/custom-select-control/style.scss',
120+
'snackbar-notice-style':
121+
'./node_modules/wordpress-components/src/snackbar/style.scss',
122+
'combobox-control-style':
123+
'./node_modules/wordpress-components/src/combobox-control/style.scss',
124+
'form-token-field-style':
125+
'./node_modules/wordpress-components/src/form-token-field/style.scss',
126+
117127
// Packages styles
118128
'packages-style': glob.sync( './packages/**/index.js' ),
119129

src/AssetsController.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,17 @@ protected function init() {
4646
* Register block scripts & styles.
4747
*/
4848
public function register_assets() {
49-
$this->register_style( 'wc-blocks-packages-style', plugins_url( $this->api->get_block_asset_build_path( 'packages-style', 'css' ), __DIR__ ), [], 'all', true );
50-
$this->register_style( 'wc-blocks-style', plugins_url( $this->api->get_block_asset_build_path( 'wc-blocks', 'css' ), __DIR__ ), [], 'all', true );
5149
$this->register_style( 'wc-blocks-editor-style', plugins_url( $this->api->get_block_asset_build_path( 'wc-blocks-editor-style', 'css' ), __DIR__ ), [ 'wp-edit-blocks' ], 'all', true );
5250

51+
if ( wc_current_theme_is_fse_theme() ) {
52+
$this->register_style( 'wc-blocks-packages-style', plugins_url( $this->api->get_block_asset_build_path( 'packages-style', 'css' ), __DIR__ ), [], 'all', true );
53+
$this->register_style( 'wc-blocks-style', plugins_url( $this->api->get_block_asset_build_path( 'wc-blocks', 'css' ), __DIR__ ), [], 'all', true );
54+
} else {
55+
56+
$this->register_style( 'wc-blocks-vendors-style', plugins_url( $this->api->get_block_asset_build_path( 'wc-blocks-vendors-style', 'css' ), __DIR__ ) );
57+
$this->register_style( 'wc-all-blocks-style', plugins_url( $this->api->get_block_asset_build_path( 'wc-all-blocks-style', 'css' ), __DIR__ ), [ 'wc-blocks-vendors-style' ], 'all', true );
58+
}
59+
5360
$this->api->register_script( 'wc-blocks-middleware', 'build/wc-blocks-middleware.js', [], false );
5461
$this->api->register_script( 'wc-blocks-data-store', 'build/wc-blocks-data.js', [ 'wc-blocks-middleware' ] );
5562
$this->api->register_script( 'wc-blocks-vendors', $this->api->get_block_asset_build_path( 'wc-blocks-vendors' ), [], false );

src/BlockTypes/AbstractBlock.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,12 @@ protected function get_block_type_script( $key = null ) {
303303
* @return string[]|null
304304
*/
305305
protected function get_block_type_style() {
306-
$this->asset_api->register_style( 'wc-blocks-style-' . $this->block_name, $this->asset_api->get_block_asset_build_path( $this->block_name, 'css' ), [], 'all', true );
306+
if ( wc_current_theme_is_fse_theme() ) {
307+
$this->asset_api->register_style( 'wc-blocks-style-' . $this->block_name, $this->asset_api->get_block_asset_build_path( $this->block_name, 'css' ), [], 'all', true );
308+
return [ 'wc-blocks-style', 'wc-blocks-style-' . $this->block_name ];
309+
}
307310

308-
return [ 'wc-blocks-style', 'wc-blocks-style-' . $this->block_name ];
311+
return [ 'wc-all-blocks-style' ];
309312
}
310313

311314
/**

webpack.config.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,12 @@ const PaymentsConfig = {
7575
*/
7676
const StylingConfig = {
7777
...sharedConfig,
78-
...getStylingConfig( { alias: getAlias() } ),
78+
...getStylingConfig( { alias: getAlias(), isClassicThemeConfig: false } ),
79+
};
80+
81+
const StylingClassicThemeConfig = {
82+
...sharedConfig,
83+
...getStylingConfig( { alias: getAlias(), isClassicThemeConfig: true } ),
7984
};
8085

8186
/**
@@ -103,4 +108,5 @@ module.exports = [
103108
SiteEditorConfig,
104109
StylingConfig,
105110
InteractivityConfig,
111+
StylingClassicThemeConfig,
106112
];

0 commit comments

Comments
 (0)