From 56601679ee9fe10aa74620cd932b3889d4595a49 Mon Sep 17 00:00:00 2001 From: Ryan Welcher Date: Wed, 2 Mar 2022 13:53:34 -0500 Subject: [PATCH 1/6] Enable accepting --webpack-copy-php flag from the CLI commands --- packages/scripts/scripts/build.js | 4 ++++ packages/scripts/scripts/start.js | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/packages/scripts/scripts/build.js b/packages/scripts/scripts/build.js index 0e3cb887cda790..19a244da48e15d 100644 --- a/packages/scripts/scripts/build.js +++ b/packages/scripts/scripts/build.js @@ -19,6 +19,10 @@ if ( hasArgInCLI( '--webpack-bundle-analyzer' ) ) { process.env.WP_BUNDLE_ANALYZER = true; } +if ( hasArgInCLI( '--webpack-copy-php' ) ) { + process.env.WP_COPY_PHP_FILES_TO_DIST = true; +} + const { status } = spawn( resolveBin( 'webpack' ), getWebpackArgs(), { stdio: 'inherit', } ); diff --git a/packages/scripts/scripts/start.js b/packages/scripts/scripts/start.js index 3bd12cc39036ee..383634ee8b46bb 100644 --- a/packages/scripts/scripts/start.js +++ b/packages/scripts/scripts/start.js @@ -21,6 +21,10 @@ if ( hasArgInCLI( '--webpack--devtool' ) ) { process.env.WP_DEVTOOL = getArgFromCLI( '--webpack--devtool' ); } +if ( hasArgInCLI( '--webpack-copy-php' ) ) { + process.env.WP_COPY_PHP_FILES_TO_DIST = true; +} + const { status } = spawn( resolveBin( 'webpack' ), [ hasArgInCLI( '--hot' ) ? 'serve' : 'watch', ...getWebpackArgs() ], From 55cf88ed2f6195b356cc19981e086a5acc214557 Mon Sep 17 00:00:00 2001 From: Ryan Welcher Date: Wed, 2 Mar 2022 13:54:22 -0500 Subject: [PATCH 2/6] Update the glob pattern based on existence of --webpack-copy-php flag. --- packages/scripts/config/webpack.config.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/scripts/config/webpack.config.js b/packages/scripts/config/webpack.config.js index 68dd39c810d410..6661b633de56ee 100644 --- a/packages/scripts/config/webpack.config.js +++ b/packages/scripts/config/webpack.config.js @@ -36,6 +36,10 @@ if ( ! browserslist.findConfig( '.' ) ) { } const hasReactFastRefresh = hasArgInCLI( '--hot' ) && ! isProduction; +const copyWebPackPattens = process.env.WP_COPY_PHP_FILES_TO_DIST + ? '**/{block.json,*.php}' + : '**/block.json'; + const cssLoaders = [ { loader: MiniCSSExtractPlugin.loader, @@ -228,12 +232,7 @@ const config = { new CopyWebpackPlugin( { patterns: [ { - from: '**/block.json', - context: 'src', - noErrorOnMissing: true, - }, - { - from: '**/**.php', + from: copyWebPackPattens, context: 'src', noErrorOnMissing: true, }, From 99fc30f021ef1ad34e18afee54ef3ddd92235476 Mon Sep 17 00:00:00 2001 From: Ryan Welcher Date: Wed, 2 Mar 2022 13:54:47 -0500 Subject: [PATCH 3/6] Update README and changelog files. --- packages/scripts/CHANGELOG.md | 1 + packages/scripts/README.md | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/scripts/CHANGELOG.md b/packages/scripts/CHANGELOG.md index 8e70fd94f7c41e..5413cbe058bbd2 100644 --- a/packages/scripts/CHANGELOG.md +++ b/packages/scripts/CHANGELOG.md @@ -1,6 +1,7 @@ ## Unreleased +- Add `--webpack-copy-php` CLI flag to opt-in to copying php files from `src` and its subfolders to the output directory (`build` by default). ## 22.0.0 (2022-02-22) diff --git a/packages/scripts/README.md b/packages/scripts/README.md index eb00747bbb7bb3..d24a0d95a7bd77 100644 --- a/packages/scripts/README.md +++ b/packages/scripts/README.md @@ -79,7 +79,8 @@ _Example:_ { "scripts": { "build": "wp-scripts build", - "build:custom": "wp-scripts build entry-one.js entry-two.js --output-path=custom" + "build:custom": "wp-scripts build entry-one.js entry-two.js --output-path=custom", + "build:copy-php": "wp-scripts build --webpack-copy-php" } } ``` @@ -88,11 +89,13 @@ This is how you execute the script with presented setup: - `npm run build` - builds the code for production. - `npm run build:custom` - builds the code for production with two entry points and a custom output folder. Paths for custom entry points are relative to the project root. +- `npm run build:copy-php` - builds the code for production and opts into copying PHP files from src src and its subfolders to the dist directory. This script automatically use the optimized config but sometimes you may want to specify some custom options: - `--webpack-no-externals` – disables scripts' assets generation, and omits the list of default externals. - `--webpack-bundle-analyzer` – enables visualization for the size of webpack output files with an interactive zoomable treemap. +- `--webpack-copy-php` – enables copying PHP files from src and its subfolders to the dist directory. #### Advanced information @@ -367,7 +370,8 @@ _Example:_ "scripts": { "start": "wp-scripts start", "start:hot": "wp-scripts start --hot", - "start:custom": "wp-scripts start entry-one.js entry-two.js --output-path=custom" + "start:custom": "wp-scripts start entry-one.js entry-two.js --output-path=custom", + "start:copy-php": "wp-scripts start" } } ``` @@ -377,6 +381,7 @@ This is how you execute the script with presented setup: - `npm start` - starts the build for development. - `npm run start:hot` - starts the build for development with "Fast Refresh". The page will automatically reload if you make changes to the files. - `npm run start:custom` - starts the build for development which contains two entry points and a custom output folder. Paths for custom entry points are relative to the project root. +- `npm run start:copy-php` - starts the build for development and opts into copying PHP files from src src and its subfolders to the dist directory. This script automatically use the optimized config but sometimes you may want to specify some custom options: @@ -384,6 +389,7 @@ This script automatically use the optimized config but sometimes you may want to - `--webpack-no-externals` – disables scripts' assets generation, and omits the list of default externals. - `--webpack-bundle-analyzer` – enables visualization for the size of webpack output files with an interactive zoomable treemap. - `--webpack--devtool` – controls how source maps are generated. See options at https://webpack.js.org/configuration/devtool/#devtool. +- `--webpack-copy-php` – enables copying PHP files from src and its subfolders to the dist directory. #### Advanced information From e89ccf95b82d2df3c4faa5c362dde1666d5d902b Mon Sep 17 00:00:00 2001 From: Ryan Welcher Date: Wed, 2 Mar 2022 14:16:51 -0500 Subject: [PATCH 4/6] Add PR to the changelog. --- packages/scripts/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/scripts/CHANGELOG.md b/packages/scripts/CHANGELOG.md index 5413cbe058bbd2..d218680d66a443 100644 --- a/packages/scripts/CHANGELOG.md +++ b/packages/scripts/CHANGELOG.md @@ -1,7 +1,7 @@ ## Unreleased -- Add `--webpack-copy-php` CLI flag to opt-in to copying php files from `src` and its subfolders to the output directory (`build` by default). +- Add `--webpack-copy-php` CLI flag to opt-in to copying php files from `src` and its subfolders to the output directory (`build` by default) ([#39171](https://github.com/WordPress/gutenberg/pull/39171)). ## 22.0.0 (2022-02-22) From 8922d7e4a2a0623aec4618f7882a9c64df3e59be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Zi=C3=B3=C5=82kowski?= Date: Thu, 3 Mar 2022 09:28:27 +0100 Subject: [PATCH 5/6] Update CHANGELOG.md --- packages/scripts/CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/scripts/CHANGELOG.md b/packages/scripts/CHANGELOG.md index d218680d66a443..8e39f58c9dd35f 100644 --- a/packages/scripts/CHANGELOG.md +++ b/packages/scripts/CHANGELOG.md @@ -1,6 +1,9 @@ ## Unreleased + +### New Feature + - Add `--webpack-copy-php` CLI flag to opt-in to copying php files from `src` and its subfolders to the output directory (`build` by default) ([#39171](https://github.com/WordPress/gutenberg/pull/39171)). ## 22.0.0 (2022-02-22) From f97acb3b8cc8b0535fe323c57f8fd4a780cda463 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Zi=C3=B3=C5=82kowski?= Date: Thu, 3 Mar 2022 09:44:18 +0100 Subject: [PATCH 6/6] Update README.md --- packages/scripts/README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/scripts/README.md b/packages/scripts/README.md index d24a0d95a7bd77..8fe5bfefb6fc42 100644 --- a/packages/scripts/README.md +++ b/packages/scripts/README.md @@ -88,14 +88,14 @@ _Example:_ This is how you execute the script with presented setup: - `npm run build` - builds the code for production. -- `npm run build:custom` - builds the code for production with two entry points and a custom output folder. Paths for custom entry points are relative to the project root. -- `npm run build:copy-php` - builds the code for production and opts into copying PHP files from src src and its subfolders to the dist directory. +- `npm run build:custom` - builds the code for production with two entry points and a custom output directory. Paths for custom entry points are relative to the project root. +- `npm run build:copy-php` - builds the code for production and opts into copying PHP files from the `src` directory and its subfolders to the output directory. This script automatically use the optimized config but sometimes you may want to specify some custom options: -- `--webpack-no-externals` – disables scripts' assets generation, and omits the list of default externals. - `--webpack-bundle-analyzer` – enables visualization for the size of webpack output files with an interactive zoomable treemap. -- `--webpack-copy-php` – enables copying PHP files from src and its subfolders to the dist directory. +- `--webpack-copy-php` – enables copying PHP files from the `src` directory and its subfolders to the output directory. +- `--webpack-no-externals` – disables scripts' assets generation, and omits the list of default externals. #### Advanced information @@ -380,16 +380,16 @@ This is how you execute the script with presented setup: - `npm start` - starts the build for development. - `npm run start:hot` - starts the build for development with "Fast Refresh". The page will automatically reload if you make changes to the files. -- `npm run start:custom` - starts the build for development which contains two entry points and a custom output folder. Paths for custom entry points are relative to the project root. -- `npm run start:copy-php` - starts the build for development and opts into copying PHP files from src src and its subfolders to the dist directory. +- `npm run start:custom` - starts the build for development which contains two entry points and a custom output directory. Paths for custom entry points are relative to the project root. +- `npm run start:copy-php` - starts the build for development and opts into copying PHP files from the `src` directory and its subfolders to the output directory. This script automatically use the optimized config but sometimes you may want to specify some custom options: - `--hot` – enables "Fast Refresh". The page will automatically reload if you make changes to the code. _For now, it requires that WordPress has the [`SCRIPT_DEBUG`](https://wordpress.org/support/article/debugging-in-wordpress/#script_debug) flag enabled and the [Gutenberg](https://wordpress.org/plugins/gutenberg/) plugin installed._ -- `--webpack-no-externals` – disables scripts' assets generation, and omits the list of default externals. - `--webpack-bundle-analyzer` – enables visualization for the size of webpack output files with an interactive zoomable treemap. -- `--webpack--devtool` – controls how source maps are generated. See options at https://webpack.js.org/configuration/devtool/#devtool. -- `--webpack-copy-php` – enables copying PHP files from src and its subfolders to the dist directory. +- `--webpack-copy-php` – enables copying PHP files from the `src` directory and its subfolders to the output directory. +- `--webpack-devtool` – controls how source maps are generated. See options at https://webpack.js.org/configuration/devtool/#devtool. +- `--webpack-no-externals` – disables scripts' assets generation, and omits the list of default externals. #### Advanced information