You can use the scripts in package.json to create new content and develop, format, build, and preview your project from a terminal window.

package.json scripts

You can add scripts to the scripts section for any commands you use frequently.

The following scripts for the most common commands (create, dev, format, build, and preview) are added for you automatically when you create a new project.

package.json
{
  "scripts": {
    "create": "hugo new",
    "dev": "hugo server --disableFastRender --noHTTPCache",
    "format": "prettier **/** -w -c",
    "build": "hugo --minify --gc",
    "preview": "vite preview --outDir public"
  }
}

You will often use these commands, or the scripts that run them, without any flags. Add flags to the command when you want to customize the command’s behavior. For example, you may wish to start the development server on a different port, or build your site with verbose logs for debugging.

The extra -- before any flag is necessary for npm to pass your flags to the script.

You can find the available flags for a command on the command’s linked script page below.

create

Run the following command in your terminal to create new content:

For example, create an about page in the content directory of your project:

dev

Run the following command in your terminal to start the Hugo development server:

format

Run the following command in your terminal to run the Prettier code formatter:

build

Run the following command in your terminal to create a production build:

preview

Run the following command in your terminal to locally preview the production build: