Build your first static site with Publican
401 words, 3-minute read
Build your site to the project’s build/
directory with the command:
terminal
node ./publican.config.js
Production mode #
By default, Publican builds a final production site for live deployment. It omits all pages where the front matter:
date
value set to a future time, orpubish
value is set tofalse
,draft
, or a future time.
Development mode #
You will want to build and view draft pages during development. This can be achieved by setting the NODE_ENV
environment variable to development
before running Publican:
Linux / Mac OS / Windows WSL terminal
NODE_ENV=development
node ./publican.config.js
Windows cmd
set NODE_ENV=development
node ./publican.config.js
Windows Powershell
$env:NODE_ENV="development"
node ./publican.config.js
Refer to the Configuration file for better ways of managing development and production builds.
Local web server #
Publican does not provide a development web server to test your built site. The following command installs a small Node.js file server package globally:
terminal
npm i small-static-server -g
You can launch a server immediately after a successful build:
terminal
node ./publican.config.js
smallserver 8000 ./build/
and test your site by opening localhost:8000
in your browser.
Other server options #
Other server options include:
Install a file server package
Node.js packages such as small-static-server (shown above) and Browsersync can serve files from any directory.
Install an editor server plugin
Plugins such as Live Server for VS Code can launch a development server.
Install a dedicated development server
Software such as Caddy can launch development sites with custom
localhost
domains and HTTPS certificates.Use your existing development server
You can add your project’s
build
directory as a web root to a development server running on your device, such as NGINX or Apache.Add esbuild to your configuration
This site uses Publican to create web pages and esbuild to bundle CSS and JavaScript. esbuild includes a local server that can live reload when CSS files are modified.