Skip to content

npm scripts automation for Hexo

npm scripts automation for Hexo involves defining custom command sequences in the package.json file to streamline the build, preview, and deployment processes of a Hexo blog.^[600-developer-blog-hexo-blog-create-blog-hexo.md] By abstracting complex Hexo CLI commands into simple npm scripts, developers can reduce typing errors and maintain a consistent workflow.^[600-developer-blog-hexo-blog-create-blog-hexo.md]

Common Scripts

A standard package.json in a Hexo project typically includes a scripts section for automation^[600-developer-blog-hexo-blog-create-blog-hexo.md].

  • clean: Clears the cache and generated files.
  • dev: Launches a local development server with specific flags for real-time feedback.^[600-developer-blog-hexo-blog-create-blog-hexo.md]
  • deploy: Performs the build and deployment steps in a single command.^[600-developer-blog-hexo-blog-create-blog-hexo.md]

Local Development

The dev script is designed to facilitate local development and debugging.^[600-developer-blog-hexo-blog-create-blog-hexo.md] It combines the hexo generate command with hexo server using the -w flag (watch mode) and --debug flag^[600-developer-blog-hexo-blog-create-blog-hexo.md]. Additionally, it enables --drafts so that draft posts can be reviewed locally before publication^[600-developer-blog-hexo-blog-create-blog-hexo.md].

Deployment

The deploy script automates the publishing process^[600-developer-blog-hexo-blog-create-blog-hexo.md]. This script chains hexo generate to build the static site and hexo deploy to push the content to the configured repository (e.g., GitHub Pages)^[600-developer-blog-hexo-blog-create-blog-hexo.md].

  • [[Hexo]]
  • [[npm scripts]]
  • [[Continuous deployment]]

Sources

^[600-developer-blog-hexo-blog-create-blog-hexo.md]