-
Notifications
You must be signed in to change notification settings - Fork 0
Scripts
Gabriela Carral edited this page Apr 30, 2025
·
1 revision
This document provides detailed information about all the Node.js scripts available in this theme, their purposes, and how to use them effectively.
- Development Scripts
- Code Quality Scripts
- Distribution Scripts
- Maintenance Scripts
- Gulp Tasks
- Configuration Files
- Environment Variables
- Best Practices
wp-scripts start --webpack-src-dir=assets/js/src --config=./config/webpack.config.js & gulp watch- Purpose: Starts the development environment with live reload
-
What it does:
- Runs Webpack in watch mode for JavaScript/SCSS compilation
- Starts BrowserSync for live reload
- Watches for file changes
- Automatically compiles SCSS to CSS
- Bundles JavaScript modules
- Optimizes images on the fly
- When to use: During active development
-
Configuration files:
config/webpack.config.jsgulpfile.js
wp-scripts build --webpack-src-dir=assets/js/src --config=./config/webpack.config.js && gulp build- Purpose: Creates production-ready assets
-
What it does:
- Compiles and minifies JavaScript
- Compiles and optimizes SCSS to CSS
- Optimizes images
- Creates sourcemaps
- Applies production optimizations
- When to use: Before deploying to production
- Output: Optimized assets in their respective directories
wp-scripts format- Purpose: Formats code according to WordPress coding standards
-
What it does:
- Formats JavaScript files
- Formats SCSS files
- Maintains consistent code style
- When to use: Before committing code changes
wp-scripts lint-js- Purpose: Checks JavaScript code for errors and style issues
-
What it does:
- Runs ESLint with WordPress configuration
- Reports JavaScript code issues
- When to use: During development and before commits
wp-scripts lint-js --fix- Purpose: Automatically fixes JavaScript code style issues
-
What it does:
- Runs ESLint with --fix option
- Automatically corrects fixable issues
- When to use: When lint:js reports fixable issues
wp-scripts lint-style- Purpose: Checks SCSS/CSS code for errors and style issues
-
What it does:
- Runs Stylelint with WordPress configuration
- Reports SCSS/CSS code issues
- When to use: During development and before commits
wp-scripts lint-style --fix- Purpose: Automatically fixes SCSS/CSS code style issues
-
What it does:
- Runs Stylelint with --fix option
- Automatically corrects fixable issues
- When to use: When lint:css reports fixable issues
gulp zip- Purpose: Creates a distributable ZIP archive of the theme
-
What it does:
- Excludes development files (node_modules, source files, etc.)
- Includes only production-necessary files
- Names the ZIP file with theme name and version
- When to use: When preparing the theme for distribution
-
Output:
wptsp-{version}.zipin the root directory
gulp version-sync && conventional-changelog -p angular -i CHANGELOG.md -s && git add . && git commit -m 'chore: version bump'- Purpose: Updates theme version across all necessary files
-
What it does:
- Syncs version in style.css and theme.json
- Updates CHANGELOG.md with new changes
- Creates a version commit
- When to use: When releasing a new version
wp-scripts packages-update- Purpose: Updates WordPress npm packages
-
What it does:
- Checks for updates to @wordpress/* packages
- Updates package.json
- Updates package-lock.json
- When to use: Periodically to keep dependencies updated
wp i18n make-pot . languages/theme-textdomain.pot --exclude=vendor,node_modules- Purpose: Generates translation template file
-
What it does:
- Scans theme files for translatable strings
- Creates/updates POT file
- Excludes vendor and node_modules directories
- When to use: When adding/modifying translatable strings
The theme uses Gulp for various build and optimization tasks. These tasks are integrated into the npm scripts above but can also be run individually using gulp:
-
gulp images- Optimize images -
gulp zip- Create theme ZIP file -
gulp version-sync- Sync version across theme files -
gulp watch- Watch for file changes -
gulp browserSync- Start BrowserSync server -
gulp build- Run production build tasks
-
Webpack:
config/webpack.config.js- Entry points configuration
- Output settings
- Alias definitions
- Build optimizations
-
Babel:
.babelrc.js- JavaScript transpilation settings
- WordPress preset configuration
-
Gulp:
gulpfile.js- Task definitions
- File paths
- Build process configuration
-
WP_HOME: WordPress installation URL (default: "http://localhost:10000")- Used by BrowserSync for local development
- Can be set in
.envfile
-
Development Workflow:
- Always run
npm run devduring development - Use linting commands before committing
- Run
npm run buildbefore testing production builds
- Always run
-
Version Control:
- Run format and lint commands before commits
- Use
npm run versionfor version bumps - Generate POT files when adding strings
-
Production Deployment:
- Update version number in package.json
- Run
npm run version - Run
npm run build - Run
npm run zip - Test the generated ZIP file
-
Maintenance:
- Regularly run
npm run packages-update - Keep dependencies updated
- Maintain changelog entries
- Regularly run