This document describes the build system used to process and bundle frontend assets for the Multisite Language Switcher plugin. It covers the npm-based build pipeline that transforms source JavaScript, LESS stylesheets, and Gutenberg block code into production-ready assets. The build system handles three primary asset types: minified JavaScript for the admin interface, compiled and minified CSS, and bundled Gutenberg block code.
For information about testing infrastructure, see Testing Framework. For CI/CD workflows that invoke these build steps, see CI/CD and Deployment.
The build system relies on npm packages defined in package.json1-22 The plugin uses a minimal set of production dependencies for asset processing, with additional development dependencies for testing:
| Package | Version | Purpose |
|---|---|---|
uglify-js | ^3.19.3 | JavaScript minification |
less | ^4.4.2 | LESS stylesheet compilation |
less-plugin-clean-css | ^1.6.0 | CSS minification via clean-css |
| Package | Version | Purpose |
|---|---|---|
@wordpress/scripts | ^31.1.0 | Gutenberg block bundling via webpack |
@playwright/test | ^1.57.0 | End-to-end testing |
@wordpress/e2e-test-utils | ^11.34.0 | WordPress E2E test utilities |
Sources: package.json9-20
The build system transforms source files into production-ready assets that are excluded from version control. Built assets are listed in .gitignore9-10 to prevent committing generated files.
Build Pipeline: Source to Distribution
Sources: package.json2-8 .gitignore9-10
Build tasks are defined as npm scripts in package.json2-8 Each script handles a specific asset type:
| Script | Command | Purpose |
|---|---|---|
uglify | uglifyjs src/msls.js > assets/js/msls.js | Minify admin JavaScript |
less | lessc assets/css/msls.less assets/css/msls.css --clean-css="--s1 --advanced" | Compile and minify LESS to CSS |
build-msls-block | wp-scripts build --webpack-src-dir=src/msls-widget-block --output-path=assets/js/msls-widget-block | Bundle Gutenberg block |
The build script executes all asset processing steps sequentially:
This composite script is invoked by CI/CD workflows during plugin deployment. See CI/CD and Deployment for details on automated builds.
Sources: package.json2-8
The uglify script processes a single JavaScript source file using UglifyJS:
Input: src/msls.js (source code, version-controlled)
Output: assets/js/msls.js (minified, git-ignored)
Tool: uglifyjs version ^3.19.3
The minification process:
assets/js/msls.js via shell redirectionThis JavaScript file is enqueued in the WordPress admin interface to provide autocomplete functionality in the translation linking meta boxes (see Post and Page Meta Boxes).
Sources: package.json3 package.json12
The less script compiles LESS stylesheets to CSS with integrated minification:
Input: assets/css/msls.less (LESS source, version-controlled)
Output: assets/css/msls.css (compiled and minified CSS, git-ignored)
Tools: less ^4.4.2 + less-plugin-clean-css ^1.6.0
The compilation pipeline:
lessc processes variables, mixins, and nested rulesclean-css plugin applies aggressive minification --s1: Level 1 optimizations (safe transformations)--advanced: Additional advanced optimizationsThe resulting CSS file styles admin interface elements including meta boxes, custom columns, and the language switcher widget.
Sources: package.json4 package.json10-11
The build-msls-block script bundles the language switcher Gutenberg block using WordPress's official build tools:
Input: src/msls-widget-block/ directory (React/JSX source)
Output: assets/js/msls-widget-block/ directory (bundled JS, git-ignored)
Tool: @wordpress/scripts version ^31.1.0
The @wordpress/scripts package provides a webpack-based build system configured for WordPress block development. It handles:
The webpack configuration is managed by @wordpress/scripts and includes:
The built block is registered in WordPress and renders the language switcher in the block editor. See Widgets and Gutenberg Blocks for usage details.
Sources: package.json5 package.json18
The build system includes utility scripts that generate PHP configuration files mapping language codes to flag icons. These are not part of the standard npm run build workflow but are run manually when WordPress adds new translation teams.
PNG Flag Mapping
The bin/flags-png.php1-137 script:
build/translations.jsonassets/flags/SVG Flag Mapping
The bin/flags-svg.php1-137 script follows the same pattern but:
assets/css-flags/flags/4x3/flag-icon-de instead of filenamesBoth scripts contain exception tables (bin/flags-png.php34-86 bin/flags-svg.php33-84) that manually map languages to flags when the automatic mapping fails:
Both scripts report unused flag icons at the bottom of generated files (assets/flags/flags.php141-156 assets/css-flags/flags.php141-156), helping maintainers identify which flag assets could be removed to reduce package size.
Sources: bin/flags-png.php1-137 bin/flags-svg.php1-137 assets/flags/flags.php1-157 assets/css-flags/flags.php1-157
The build system integrates with the plugin's development and deployment workflows:
Complete Build Workflow
Developers work with source files and run npm run build locally to generate assets for testing. Built assets in assets/js/ are excluded from version control via .gitignore9-10
The deployment workflow (see CI/CD and Deployment) rebuilds all assets in a clean environment:
composer run-script build installs npm dependenciesnpm run build generates fresh assetsThis ensures that distributed plugin packages always contain properly built assets, even though they're not committed to git.
Sources: package.json2-8 .gitignore9-10
Built assets are included in the distributed plugin but excluded from the git repository:
src/msls.js - JavaScript sourceassets/css/msls.less - LESS sourcesrc/msls-widget-block/ - Gutenberg block sourcepackage.json - Build configurationpackage-lock.json - Dependency lock fileassets/js/msls.js - Minified JavaScriptassets/js/msls-widget-block/ - Bundled Gutenberg blocknode_modules/ - npm dependenciesThe .distignore file (see WordPress.org Integration) controls which files are excluded from the WordPress.org SVN repository. Built assets are included in the distribution package, while development tools (node_modules/, tests/, etc.) are excluded.
Sources: .gitignore9-10 package.json1-22
Refresh this wiki
This wiki was recently refreshed. Please wait 1 day to refresh again.