The command saber build creates a public directory with a production build of your app. Set up your favorite HTTP server to properly serve static .html files and other static assets.
Built-in Static Server
You can use the built-in static server via the saber serve command, it automatically serves the public directory:
cd my-site
yarn saber build
yarn saber serveThis is great for previewing the production build locally.
Other Solutions
You don't need the built-in static server in order to serve a Saber application, it works just fine with most static servers, for example you can use sirv-cli:
npx sirv-cli publicOr serve:
npx serve publicBuilding for Relative Paths
By default, Saber produces a build assuming your app is hosted at the server root.
To override this, specify the build.publicUrl in your Saber config file, for example:
// saber.config.js
module.exports = {
build: {
publicUrl: '/blog/'
}
}Netlify
To setup continuous delivery:
With this setup Netlify will build and deploy when you push to git or open a pull request:
- Start a new netlify project
- Pick your Git hosting service and select your repository
- Click
Build your site
Since Netlify automatically rewrites routes like /foo to /foo.html when /foo doesn't exist, you may need saber-plugin-netlify-redirect to fix this.
GitHub Pages
Step 1: Install gh-pages and add deploy to scripts in package.json
npm i -D gh-pagesAlternatively you may use yarn:
yarn add gh-pages --devAdd the following scripts in your package.json:
"scripts": {
+ "predeploy": "npm run build",
+ "deploy": "gh-pages -d public -t",
"dev": "saber",
"build": "saber build",
Step 2: Add .nojekyll to turn off Jekyll
Adding a file .nojekyll (with empty content) to the static/ folder to turn off Jekyll integration of GitHub Pages.
Step 3: Optionally, configure the domain or repository path
If you are using a custom domain, you can configure it with GitHub Pages by adding a CNAME file to the static/ folder.
Your CNAME file should look like this:
mywebsite.comIf you are using a repository-level gh-pages deployment ([username].github.io/[repository name]), set the publicUrl property in the Saber configuration file. This is not required for account-level gh-pages deployments ([username].github.io).
Step 4: Deploy the site by running npm run deploy
Then run:
npm run deploy Step 5: For a project page, ensure your project’s settings use gh-pages
Finally, make sure GitHub Pages option in your GitHub project settings is set to use the gh-pages branch: