Commands to start development env
For Webpack
Section titled “For Webpack”Webpack projects manage everything from package.json scripts, including building and deploying.
"scripts": { "virtual": "webpack serve --config webpack.dev.js --open", "local": "webpack --config webpack.prod.js", "production": "webpack --config webpack.prod.js", "dev-full": "gulp deploy_full", "stg-hash": "gulp deploy_hash", "prd-file": "gulp deploy_file --file"}Development and Build
Section titled “Development and Build”- Starts a live dev server (local preview) →
npm run virtual - Builds the project and creates dist →
npm run local or npm run production
Deployment by environment
Section titled “Deployment by environment”These are pre-configured shortcuts that run the correct Gulp tasks for each environment.
- Full deployment to development →
npm run dev-full - Deploy hash build to staging →
npm run stg-hash - Upload a single file to production →
npm run prd-file
For Vite
Section titled “For Vite”In your package.json, you’ll find these scripts:
"scripts": { "virtual": "cross-env NODE_ENV=virtual vite", "local": "NODE_ENV=local vite build", "build": "NODE_ENV=production vite build"}npm run virtual
Section titled “npm run virtual”Starts the project in a special “virtual” environment. Useful for development and testing with real data or mock content.
npm run local
Section titled “npm run local”Builds the project using local settings. It prepares the output files but does not upload or preview anything.
npm run build
Section titled “npm run build”Builds the project with production settings.
It creates a folder called dist and adds a short code (hash) of three characters to the filenames, like main.ab2.js.
To automatically change these generated hashs into our hash.php document, we added this function to our wp-starter-kit’s viteHelper.js:
export function updateHash(hash) { console.log(`Updating hash in hash.php file with new hash: ${hash}`);
const hashFileRoute = resolve(process.cwd(), "functions/project/hash.php");
if (fsSync.existsSync(hashFileRoute)) { const content = fsSync.readFileSync(hashFileRoute, "utf-8");
const updatedContent = content.replace( /define\(\s*['"]hash['"]\s*,\s*['"][a-zA-Z0-9]*['"]\s*\);/, `define('hash', '${hash}');` );
fsSync.writeFileSync(hashFileRoute, updatedContent, "utf-8"); } else { console.log("Hash file not found:", hashFileRoute); }}Upload (Deploy) the Project
Section titled “Upload (Deploy) the Project”All the following commands use this format:
gulp <task> --dev|stage|production🔸 gulp ddist —dev|stage|production
Section titled “🔸 gulp ddist —dev|stage|production”Uploads everything inside the dist folder.
🔸 gulp ddisthash —dev|stage|production
Section titled “🔸 gulp ddisthash —dev|stage|production”Uploads the dist folder and the hash folder (which includes the version info).
This is what you normally run after npm run build.
🔸 gulp dfm —dev|stage|production
Section titled “🔸 gulp dfm —dev|stage|production”Deploy all flexible modules (custom reusable blocks).
🔸 gulp dall —dev|stage|production
Section titled “🔸 gulp dall —dev|stage|production”Deploy all files (PHP, JS, assets, modules…).
🔸 gulp dphp —dev|stage|production
Section titled “🔸 gulp dphp —dev|stage|production”Deploy only the PHP files.
🔸 gulp ds —dev|stage|production —path file|folder
Section titled “🔸 gulp ds —dev|stage|production —path file|folder”Deploy just one file or one folder.
🔸 gulp remove —dev|stage|production —path file|folder
Section titled “🔸 gulp remove —dev|stage|production —path file|folder”Deletes a file or folder from the server.
Extra Tools
Section titled “Extra Tools”nvm use
Section titled “nvm use”Switches your Node.js version to the one your project needs. Important if you’re switching between different projects or machines.
# Use Node.js version 21nvm use 21# Check the version usenode -vnpm cache clean —force
Section titled “npm cache clean —force”Sometimes npm gives errors. This command clears the cache.
Knowledge Check
Test your understanding of this section
Loading questions...