Skip to content

Commands to start development env


Webpack projects manage everything from package.json scripts, including building and deploying.

Terminal window
"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"
}
  • Starts a live dev server (local preview) → npm run virtual
  • Builds the project and creates dist → npm run local or npm run production

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

In your package.json, you’ll find these scripts:

Terminal window
"scripts": {
"virtual": "cross-env NODE_ENV=virtual vite",
"local": "NODE_ENV=local vite build",
"build": "NODE_ENV=production vite build"
}

Starts the project in a special “virtual” environment. Useful for development and testing with real data or mock content.

Builds the project using local settings. It prepares the output files but does not upload or preview anything.

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);
}
}

All the following commands use this format:

Terminal window
gulp <task> --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.

Deploy all flexible modules (custom reusable blocks).

Deploy all files (PHP, JS, assets, modules…).

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.

Switches your Node.js version to the one your project needs. Important if you’re switching between different projects or machines.

Terminal window
# Use Node.js version 21
nvm use 21
Terminal window
# Check the version use
node -v

Sometimes npm gives errors. This command clears the cache.


Knowledge Check

Test your understanding of this section

Loading questions...