# Exporting to static HTML
Fractal provides the option to export the web UI view into static HTML files, which can quickly and easily be shared with clients or hosted using a simple static file server.
TIP
When developing locally you'll want to use the local development server to preview your project while you work on it, rather than running repeated exports after changes have been made.
# Configuration
Before you can run the build step you need to set a build destination for your Fractal instance:
fractal.web.set('builder.dest', __dirname + '/build');
# Running the build
You can either start the export using the Fractal CLI tool (if you are using it) or programmatically using Fractal's API.
# Using the CLI tool
You can use the build
command from within the root of your project to get the server up and running:
fractal build
You can provide the following optional command line options to override the default configuration:
-t, --theme <theme-name>
- a custom theme to use.
# Programmatically
If you wish to start the export process programmatically, (often useful for build tool integrations), you can create a new builder instance using the fractal.web.builder()
method and then start it as required:
const builder = fractal.web.builder();
builder.build().then(function(){
console.log(`Fractal static HTML build complete!`);
});
The Builder
object returned by the call to fractal.web.builder()
is a Node EventEmitter and will emit error events (and others) that you can bind to. See the fractal.web
API docs for full details.