Commands Reference
MarkStack provides a set of npm scripts for building, developing, and previewing your site. This page documents each command in detail.
Available Commands
| Command | Purpose |
|---|---|
npm run build |
Build the site for production |
npm run watch |
Build and rebuild on file changes |
npm run clean |
Delete the dist folder |
npx serve dist |
Preview the built site locally |
npm run build
The build command generates your complete site in the dist/ folder.
Usage
npm run build
What It Does
- Clears any existing
dist/folder - Copies all files from
static/todist/ - Builds the URL map from content titles
- Processes every markdown file in
content/ - Generates HTML pages using the template
- Creates the homepage and 404 page
- Generates
search-index.jsonfor search functionality
Output
π¨ Building MarkStack...
β Copied static files
β Generated: /getting-started/
β Generated: /getting-started/installation/
β Generated: /getting-started/quickstart/
β Generated: /authoring/
β Generated: /authoring/markdown-features/
...
β Generated: / (homepage)
β Generated: /404.html
β Generated: /search-index.json (42 pages)
β
Build complete in 127ms
π Output: C:\Users\...\MarkStack\dist
When to Use
- Before deploying to production
- After making content changes you want to preview
- To generate a clean build for testing
npm run watch
The watch command builds the site and then watches for file changes, automatically rebuilding when you save.
Usage
npm run watch
What It Does
- Performs an initial build (same as
npm run build) - Watches the following directories for changes:
content/- Markdown filesstatic/- CSS, JavaScript, imagestemplates/- HTML templates
- When a file changes, rebuilds the entire site
Output
π Watching for changes...
π¨ Building MarkStack...
β Copied static files
β Generated: /getting-started/
...
β
Build complete in 127ms
π Changed: content\authoring\examples.md
π¨ Building MarkStack...
...
β
Build complete in 132ms
When to Use
- During content development
- When writing or editing documentation
- When adjusting styles or templates
TIP Run
npm run watchin one terminal andnpx serve distin another. As you save files, the site rebuilds automatically and you can refresh your browser to see changes.
File Watching Details
The watcher uses chokidar, a reliable cross-platform file watching library. It detects:
- File modifications (content changes)
- File additions (new pages)
- File deletions (removed pages)
Each detected change triggers a full rebuild to ensure navigation and search index stay current.
npm run clean
The clean command removes the dist/ folder entirely.
Usage
npm run clean
What It Does
Deletes the dist/ directory and all its contents recursively.
Output
The command runs silently. To verify:
npm run clean
ls dist # Should show "dist does not exist" or similar error
When to Use
- Before a fresh build to ensure no stale files
- When troubleshooting build issues
- To reduce folder size before archiving the project
Note: The build command already clears dist/ before building, so clean is optional in most workflows.
npx serve dist
The serve command runs a local HTTP server to preview your built site.
Usage
npx serve dist
What It Does
Starts a static file server using the serve package, hosting the contents of dist/ at http://localhost:3000.
Output
βββββββββββββββββββββββββββββββββββββββββββ
β β
β Serving! β
β β
β - Local: http://localhost:3000 β
β - Network: http://192.168.1.50:3000 β
β β
βββββββββββββββββββββββββββββββββββββββββββ
Options
Specify a different port:
npx serve dist -l 8080
Disable directory listing:
npx serve dist --no-clipboard
When to Use
- To preview the site before deployment
- To test on mobile devices (use the network URL)
- To verify the production build works correctly
Alternative: Python Server
If you have Python installed:
cd dist
python -m http.server 3000
Alternative: VS Code Live Server
If you use VS Code, you can right-click dist/index.html and select βOpen with Live Serverβ (requires the Live Server extension).
Combined Development Workflow
For active development, use two terminal windows:
Terminal 1: Watch Mode
npm run watch
Keep this running. It rebuilds automatically when you save files.
Terminal 2: Local Server
npx serve dist
Open http://localhost:3000 in your browser. Refresh after saves to see changes.
Workflow Steps
- Start watch mode in terminal 1
- Start server in terminal 2
- Open browser to localhost:3000
- Edit markdown files in your editor
- Save the file
- Wait for rebuild message in terminal 1
- Refresh browser to see changes
- Repeat steps 4-7
Build Script Internals
The build process is handled by build.js, a single-file static site generator. Key stages:
1. URL Map Generation
Scans all content and builds a mapping from file paths to URL slugs based on page titles.
2. Markdown Processing
Uses markdown-it with plugins:
markdown-it-anchorfor heading linksmarkdown-it-footnotefor footnotesmarkdown-it-task-listsfor checkboxes- Custom plugin for GitHub-style alerts
3. Navigation Building
Builds the sidebar tree and breadcrumbs by walking the directory structure.
4. Template Application
Replaces placeholders in templates/base.html with generated content.
5. Search Index
Creates a JSON file with page titles, URLs, and plain-text content for client-side search.
Troubleshooting
Build Fails with βCannot find moduleβ
Dependencies are not installed:
npm install
npm run build
Watch Mode Does Not Detect Changes
Chokidar may have issues with certain file systems. Try:
# Stop watch mode (Ctrl+C)
npm run build # Manual build
Port Already in Use
If port 3000 is taken:
npx serve dist -l 8080
Or find and stop the process using port 3000.
Changes Not Appearing
- Verify the file saved (check editor)
- Check terminal for rebuild confirmation
- Hard refresh browser (Ctrl+Shift+R or Cmd+Shift+R)
- Clear browser cache
NOTE The build script clears and regenerates
dist/on every build. Any manual changes to files indist/will be overwritten.