-
Notifications
You must be signed in to change notification settings - Fork 74
Add JavaScript/CSS build pipeline with @wordpress/scripts #227
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e8b39e3
Initial plan
Copilot ca0d46d
Setup JavaScript/CSS pipeline with @wordpress/scripts
Copilot 07faf74
Improve webpack config with documentation and helper function
Copilot 0254d8c
Build production assets with correct filenames
Copilot 8eb8d17
Generate both source and minified assets, load conditionally based on…
Copilot 2417215
Remove .asset.php files and exclude them from repository
Copilot 4127449
Remove /src directory, use assets as source files
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| module.exports = { | ||
| extends: [ 'plugin:@wordpress/eslint-plugin/recommended' ], | ||
| globals: { | ||
| jQuery: 'readonly', | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| { | ||
| "name": "wp-multi-network", | ||
| "version": "2.7.0", | ||
| "description": "A Network Management Interface for global administrators in WordPress Multisite installations", | ||
| "private": true, | ||
| "scripts": { | ||
| "build": "npm run backup-source && wp-scripts build && npm run rename-assets && npm run restore-source && npm run generate-rtl-source && npm run cleanup-assets", | ||
| "backup-source": "cp wp-multi-network/assets/js/wp-multi-network.js .backup-source.js && cp wp-multi-network/assets/css/wp-multi-network.css .backup-source.css", | ||
| "restore-source": "mv .backup-source.js wp-multi-network/assets/js/wp-multi-network.js && mv .backup-source.css wp-multi-network/assets/css/wp-multi-network.css", | ||
| "rename-assets": "mv wp-multi-network/assets/css/style-wp-multi-network.min.css wp-multi-network/assets/css/wp-multi-network.min.css 2>/dev/null || true && mv wp-multi-network/assets/css/style-wp-multi-network.min-rtl.css wp-multi-network/assets/css/wp-multi-network-rtl.min.css 2>/dev/null || true", | ||
JJJ marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "generate-rtl-source": "npx rtlcss wp-multi-network/assets/css/wp-multi-network.css wp-multi-network/assets/css/wp-multi-network-rtl.css", | ||
| "cleanup-assets": "rm -f wp-multi-network/assets/js/*.asset.php", | ||
JJJ marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "start": "wp-scripts start", | ||
| "lint:js": "wp-scripts lint-js wp-multi-network/assets/js/", | ||
| "lint:css": "wp-scripts lint-style wp-multi-network/assets/css/", | ||
| "format": "wp-scripts format wp-multi-network/assets/", | ||
| "check-engines": "wp-scripts check-engines", | ||
| "check-licenses": "wp-scripts check-licenses" | ||
| }, | ||
| "devDependencies": { | ||
| "@babel/runtime": "^7.28.4", | ||
| "@wordpress/scripts": "^28.0.0" | ||
| }, | ||
| "engines": { | ||
| "node": ">=20.0.0", | ||
| "npm": ">=10.0.0" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| /** | ||
| * Custom Webpack Configuration for WP Multi Network | ||
| * | ||
| * This configuration extends @wordpress/scripts default webpack config | ||
| * to customize the output location and naming of built assets. | ||
| * | ||
| * NOTE: Due to how webpack handles CSS extraction from JavaScript imports, | ||
| * the CSS files are generated with auto-generated chunk names that include | ||
| * a 'style-' prefix (e.g., 'style-wp-multi-network.css'). To maintain | ||
| * backward compatibility with the existing plugin structure, we use a | ||
| * post-build rename script (see package.json 'rename-assets') to rename | ||
| * these files to match the expected names ('wp-multi-network.css'). | ||
| * | ||
| * @see https://webpack.js.org/configuration/ | ||
| */ | ||
|
|
||
| const defaultConfig = require( '@wordpress/scripts/config/webpack.config' ); | ||
| const MiniCssExtractPlugin = require( 'mini-css-extract-plugin' ); | ||
| const RtlCssPlugin = require( 'rtlcss-webpack-plugin' ); | ||
| const path = require( 'path' ); | ||
|
|
||
| /** | ||
| * Helper function to generate CSS filename based on chunk name | ||
| * | ||
| * @param {Object} pathData - Webpack path data object | ||
| * @param {string} suffix - Optional suffix for the filename (e.g., '-rtl') | ||
| * @return {string} The CSS filename | ||
| */ | ||
| function getCssFilename( pathData, suffix = '' ) { | ||
| if ( pathData.chunk && pathData.chunk.name ) { | ||
| // The chunk name includes '.min', so we just add the suffix and extension | ||
| return 'css/' + pathData.chunk.name + suffix + '.css'; | ||
JJJ marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| return 'css/[name]' + suffix + '.css'; | ||
| } | ||
|
|
||
| module.exports = { | ||
| ...defaultConfig, | ||
JJJ marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| entry: { | ||
| 'wp-multi-network.min': path.resolve( process.cwd(), '.build-script.js' ), | ||
JJJ marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| output: { | ||
| path: path.resolve( process.cwd(), 'wp-multi-network/assets' ), | ||
| filename: 'js/[name].js', | ||
| }, | ||
| plugins: [ | ||
| // Remove default CSS plugins and replace with custom configuration | ||
| // to place CSS files in the css/ subdirectory with proper naming. | ||
| // @wordpress/scripts generates CSS chunks with auto-generated names | ||
| // (e.g., 'style-wp-multi-network') which we need to customize. | ||
| ...defaultConfig.plugins.filter( | ||
| ( plugin ) => | ||
| ! ( plugin instanceof MiniCssExtractPlugin ) && | ||
| ! ( plugin instanceof RtlCssPlugin ) | ||
| ), | ||
| new MiniCssExtractPlugin( { | ||
| filename: ( pathData ) => getCssFilename( pathData ), | ||
| } ), | ||
| new RtlCssPlugin( { | ||
| filename: ( pathData ) => getCssFilename( pathData, '-rtl' ), | ||
| } ), | ||
| ], | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| th.column-title { | ||
| width: 35%; | ||
| } | ||
| th.column-path { | ||
| width: 15%; | ||
| } | ||
| th.column-blogs { | ||
| width: 10%; | ||
| } | ||
| td.column-domain { | ||
| white-space: nowrap; | ||
| overflow: hidden; | ||
| } | ||
|
|
||
| .edit-network label span.scheme { | ||
| display: inline-block; | ||
| } | ||
|
|
||
| .edit-network .form-field label input[type="text"] { | ||
| width: 50%; | ||
| display: inline-block; | ||
| } | ||
|
|
||
| #poststuff #wpmn-edit-network-assign-sites .inside { | ||
| margin: 0; | ||
| padding: 0; | ||
| } | ||
|
|
||
| #wpmn-edit-network-publish .submitbox, | ||
| #wpmn-move-site-publish .submitbox { | ||
| margin: 10px -12px -12px; | ||
| } | ||
|
|
||
| #wpmn-edit-network-publish #major-publishing-actions, | ||
| #wpmn-move-site-publish #major-publishing-actions { | ||
| margin-top: 10px; | ||
| } | ||
|
|
||
| #misc-publishing-actions #network:before, | ||
| #misc-publishing-actions #sites:before { | ||
| font: normal 20px/1 dashicons; | ||
| speak: none; | ||
| display: inline-block; | ||
| padding: 0 0 0 2px; | ||
| top: 0; | ||
| right: -1px; | ||
| position: relative; | ||
| vertical-align: top; | ||
| -webkit-font-smoothing: antialiased; | ||
| -moz-osx-font-smoothing: grayscale; | ||
| text-decoration: none !important; | ||
| } | ||
|
|
||
| #misc-publishing-actions #network:before { | ||
| content: '\f319'; | ||
| } | ||
|
|
||
| #misc-publishing-actions #sites:before { | ||
| content: '\f325'; | ||
| } | ||
|
|
||
| table.widefat.move-site, | ||
| table.widefat.assign-sites { | ||
| border: none; | ||
| box-shadow: none; | ||
| } | ||
|
|
||
| table.move-site thead th, | ||
| table.assign-sites thead th { | ||
| text-align: center; | ||
| font-size: 13px; | ||
| font-weight: 600; | ||
| background: #f4f4f4; | ||
| } | ||
|
|
||
| .networks tbody td, | ||
| .networks tbody th { | ||
| -webkit-box-shadow: inset 0 -1px 0 rgba(0, 0, 0, .1); | ||
| box-shadow: inset 0 -1px 0 rgba(0, 0, 0, .1); | ||
| padding: 10px 9px; | ||
| } | ||
|
|
||
| .networks .current th.check-column { | ||
| border-right: 4px solid #00a0d2; | ||
| } | ||
|
|
||
| .networks .current td, | ||
| .networks .current th { | ||
| background-color: #f7fcfe; | ||
| padding: 10px 9px; | ||
| } | ||
|
|
||
| table.assign-sites select[multiple] { | ||
| width: 100%; | ||
| height: 80px !important; | ||
| margin: 0; | ||
| } | ||
|
|
||
| table.assign-sites .button { | ||
| margin: 0 5px; | ||
| width: 35%; | ||
| height: 80px; | ||
| } | ||
|
|
||
| table.assign-sites td.column-actions { | ||
| width: 16%; | ||
| padding: 8px 0; | ||
| } | ||
|
|
||
| table.assign-sites td.column-actions .assign { | ||
| float: right; | ||
| content: "\f341"; | ||
| } | ||
|
|
||
| table.assign-sites td.column-actions .unassign { | ||
| float: left; | ||
| } | ||
|
|
||
| table.assign-sites td.column-available { | ||
| padding-left: 0; | ||
| } | ||
|
|
||
| table.assign-sites td.column-assigned { | ||
| padding-right: 0; | ||
| } | ||
| table.assign-sites td.column-available, | ||
| table.assign-sites td.column-assigned { | ||
| width: 42%; | ||
| } | ||
|
|
||
| table.assign-sites td.column-assigned { | ||
| text-align: left; | ||
| } | ||
|
|
||
| div.network-delete { | ||
| background: #fff; | ||
| border-right: 4px solid #dc3232; | ||
| -webkit-box-shadow: 0 1px 1px 0 rgba( 0, 0, 0, 0.1 ); | ||
| box-shadow: 0 1px 1px 0 rgba( 0, 0, 0, 0.1 ); | ||
| margin: 5px 0 2px; | ||
| padding: 1px 12px; | ||
| } | ||
|
|
||
| div.network-delete p { | ||
| margin: 0.5em 0; | ||
| padding: 2px; | ||
| } | ||
|
|
||
| ul.delete-sites { | ||
| list-style: square; | ||
| margin: 10px 20px; | ||
| } | ||
|
|
||
| ul.delete-sites li { | ||
| margin: 0; | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.