Coralite Scripts
coralite-scripts is the official development and build tool for Coralite projects. It provides a complete development environment with live reloading, hot CSS updates, and a production build system optimized for static site generation.
Table of Contents #
- Overview
- Installation & Setup
- Configuration Reference
- CLI Commands
- Development Server Features
- Build Process
- API Reference
- Examples
- Troubleshooting
Overview #
coralite-scripts provides two main modes of operation:
Development Mode
Start a local server with live reload, hot CSS injection, and real-time file watching. Perfect for rapid development.
Build Mode
Compile your site for production with optimized HTML, CSS, and static assets.
Key Features #
- Live Reload - Automatic browser refresh on HTML, template, and asset changes
- Hot CSS Updates - Instant CSS injection without page refresh via Server-Sent Events
- Sass/SCSS Support - Compile Sass files with source maps and auto-prefixing
- File Watching - Monitors all source directories for changes
- Production Optimization - Clean builds with optimized output
- Plugin Integration - Full support for Coralite plugins
Installation & Setup #
Install coralite-scripts as a dev dependency in your Coralite project:
npm install --save-dev coralite-scripts
Project Structure #
Ensure your project follows the standard Coralite structure:
my-coralite-site/
βββ src/
β βββ pages/ # Page templates (.html)
β βββ templates/ # Reusable components
β βββ scss/ # Sass/SCSS files
βββ public/ # Static assets
βββ coralite.config.js # Configuration file
βββ package.json # Scripts & dependencies
package.json Scripts #
Add the following scripts to your package.json:
{
"scripts": {
"dev": "coralite-scripts dev",
"build": "coralite-scripts build",
"start": "coralite-scripts dev"
}
}
Configuration File #
Create coralite.config.js in your project root:
import { defineConfig } from 'coralite-scripts'
export default defineConfig({
output: './dist',
public: './public',
pages: './src/pages',
templates: './src/templates',
styles: {
type: 'scss',
input: './src/scss'
},
server: {
port: 3000
}
})
Configuration Reference #
The defineConfig() function validates and returns your configuration object. All properties are required unless marked as optional.
Required Properties #
| Property | Type | Description |
|---|---|---|
output |
string |
Output directory for compiled site (e.g., './dist') |
public |
string |
Directory containing static assets to copy to output |
pages |
string |
Directory containing page templates (.html files) |
templates |
string |
Directory containing reusable template components |
Optional Properties #
| Property | Type | Description |
|---|---|---|
server.port |
number |
Development server port (default: 3000) |
styles.type |
'css' | 'sass' | 'scss' |
Style processing type |
styles.input |
string |
Directory containing style files to compile |
sassOptions |
Options |
Additional Sass compiler options |
cssPlugins |
AcceptedPlugin[] |
PostCSS plugins array |
plugins |
CoralitePluginInstance[] |
Coralite plugin instances |
Configuration Validation #
The defineConfig() function performs validation and will throw errors for:
- Missing required properties
- Invalid property types
- Invalid style types (must be 'css', 'sass', or 'scss')
- Invalid server port numbers
CLI Commands #
coralite-scripts provides two main commands for development and production builds.
Development Server #
Start the development server with live reload and hot CSS updates:
npm run dev
# or
coralite-scripts dev
Options
-v, --verbose- Enable verbose logging output
What It Does
- Initializes Coralite with your configuration
- Compiles Sass/SCSS if configured
- Starts Express server on configured port
- Watches for file changes in pages, templates, and styles directories
- Injects live reload scripts into HTML pages
- Serves static assets from public directory
Production Build #
Build your site for production deployment:
npm run build
# or
coralite-scripts build
What It Does
- Cleans the output directory
- Compiles all pages with Coralite
- Saves rendered HTML to output directory
- Copies static assets from public directory
- Compiles Sass/SCSS to CSS with source maps
- Optimizes output for production
Development Server Features #
Live Reload #
Automatic browser refresh when files change:
- HTML Pages - Changes to
.htmlfiles in pages directory - Templates - Changes to template components
- Static Assets - Changes in public directory
Hot CSS Updates #
Instant CSS injection without page refresh:
- Sass/SCSS files are compiled automatically
- CSS is injected via Server-Sent Events (SSE)
- Page maintains current scroll position and state
- Works with multiple browser tabs simultaneously
File Watching #
Monitors the following directories for changes:
config.pages- Page templatesconfig.templates- Reusable componentsconfig.public- Static assetsconfig.styles.input- Sass/SCSS files
Request Logging #
Real-time terminal output showing:
- Request method and path
- HTTP status code
- Response time in milliseconds
- Compilation time for dynamic pages
Server-Sent Events (SSE) #
The development server provides a /_/rebuild endpoint that clients can connect to for real-time updates. The server sends two types of messages:
data: connected- Initial connection confirmationdata: reload- Trigger page reload
Build Process #
The production build process is optimized for performance and clean output.
Build Steps #
- Clean Output - Deletes existing output directory
- Compile HTML - Processes all pages with Coralite
- Save Documents - Writes rendered HTML to disk
- Copy Assets - Copies static files from public directory
- Compile Styles - Processes Sass/SCSS or CSS
- Generate Source Maps - Creates .map files for debugging
Sass Compilation #
When styles.type is set to 'sass' or 'scss':
- Compiles all
.scssfiles (excluding partials starting with_) - Outputs to
output/css/directory - Generates source maps by default
- Includes
node_modulesin Sass load paths - Suppresses common deprecation warnings
CSS Processing #
When styles.type is set to 'css':
- Processes CSS files through PostCSS
- Supports custom PostCSS plugins via
cssPlugins - Outputs to
output/css/directory
API Reference #
defineConfig(options) #
Defines and validates the Coralite configuration for your project.
import { defineConfig } from 'coralite-scripts'
const config = defineConfig({
output: './dist',
public: './public',
pages: './src/pages',
templates: './src/templates',
styles: {
type: 'scss',
input: './src/scss'
},
server: {
port: 3000
},
// Coralite plugins
plugins: [
// Your plugin instances
],
// Sass options
sassOptions: {
// Custom Sass compiler options
},
// PostCSS plugins
cssPlugins: [
// Your PostCSS plugins
]
})
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
options |
CoraliteScriptConfig |
Yes | Configuration object with required and optional properties |
Returns
CoraliteScriptConfig - The validated configuration object
Throws
Error- If configuration is not a valid objectError- If required properties are missing or invalidError- If optional properties have invalid types or values
Validation Rules #
| Property | Validation Rule | Error Message |
|---|---|---|
output |
Must be non-empty string | "Configuration must contain a valid "output" property" |
templates |
Must be non-empty string | "Configuration must contain a valid "templates" property" |
pages |
Must be non-empty string | "Configuration must contain a valid "pages" property" |
public |
Must be non-empty string | "Configuration must contain a valid "public" property" |
server.port |
Must be positive number | "Configuration "server.port" must be a positive number" |
styles.type |
Must be 'css', 'sass', or 'scss' | "Configuration "styles.type" must be equal to either "css", "sass" or "scss" |
styles.input |
Must be non-empty string | "Configuration "styles.input" must be a string" |
Examples #
Basic Setup #
Minimal configuration for a standard Coralite site:
import { defineConfig } from 'coralite-scripts'
export default defineConfig({
output: './dist',
public: './public',
pages: './src/pages',
templates: './src/templates'
})
Sass/SCSS Support #
Configure Sass compilation with custom options:
import { defineConfig } from 'coralite-scripts'
export default defineConfig({
output: './dist',
public: './public',
pages: './src/pages',
templates: './src/templates',
styles: {
type: 'scss',
input: './src/scss'
},
sassOptions: {
sourceMap: true,
loadPaths: ['node_modules', 'src/scss'],
silenceDeprecations: ['color-functions', 'import']
}
})
With Coralite Plugins #
Integrate Coralite plugins with coralite-scripts:
import { defineConfig } from 'coralite-scripts'
import { defineComponent } from 'coralite/plugins'
export default defineConfig({
output: './dist',
public: './public',
pages: './src/pages',
templates: './src/templates',
styles: {
type: 'scss',
input: './src/scss'
},
plugins: [
defineComponent({
// Your component definition
})
]
})
PostCSS Integration #
Use PostCSS plugins for CSS processing:
import { defineConfig } from 'coralite-scripts'
import autoprefixer from 'autoprefixer'
import cssnano from 'cssnano'
export default defineConfig({
output: './dist',
public: './public',
pages: './src/pages',
templates: './src/templates',
styles: {
type: 'css',
input: './src/css'
},
cssPlugins: [
autoprefixer(),
cssnano()
]
})
Custom Development Port #
Configure a custom port for the development server:
import { defineConfig } from 'coralite-scripts'
export default defineConfig({
output: './dist',
public: './public',
pages: './src/pages',
templates: './src/templates',
server: {
port: 8080
}
})
Complete Configuration #
Full-featured configuration with all options:
import { defineConfig } from 'coralite-scripts'
import { defineComponent, defineCollection } from 'coralite/plugins'
import autoprefixer from 'autoprefixer'
export default defineConfig({
// Required paths
output: './dist',
public: './public',
pages: './src/pages',
templates: './src/templates',
// Style processing
styles: {
type: 'scss',
input: './src/scss'
},
// Sass options
sassOptions: {
sourceMap: true,
loadPaths: ['node_modules'],
silenceDeprecations: ['import']
},
// PostCSS plugins
cssPlugins: [
autoprefixer()
],
// Development server
server: {
port: 3000
},
// Coralite plugins
plugins: [
defineComponent({
// Component definitions
}),
defineCollection({
// Collection definitions
})
]
})
Troubleshooting #
Development Server Issues #
Server won't start
Problem: Port already in use
Solution: Change the port in your config or kill the process using the port:
lsof -i :3000
kill -9 [PID]
Live reload not working
Problem: Browser not receiving SSE messages
Solutions:
- Check browser console for connection errors
- Verify file watching is working (check terminal logs)
- Ensure no browser extensions are blocking SSE
- Try a hard refresh (Ctrl+Shift+R)
Hot CSS not updating
Problem: CSS changes not reflected without page reload
Solutions:
- Check that Sass compilation is working (look for compilation logs)
- Verify CSS files are being served from
/cssroute - Check browser network tab for CSS requests
- Ensure styles are imported in HTML with correct path
Build Issues #
Build fails with errors
Problem: Compilation errors during build
Solutions:
- Check that all required directories exist
- Verify template files are valid HTML
- Check for syntax errors in Sass/SCSS files
- Ensure all Coralite plugins are properly configured
Output directory not created
Problem: Build completes but no output
Solutions:
- Check that
outputpath is valid - Verify write permissions in output directory
- Look for errors in build logs
Configuration Issues #
Config validation errors
Problem: defineConfig() throws validation errors
Solutions:
- Ensure all required properties are present
- Check property types match expected types
- Verify style type is one of: 'css', 'sass', 'scss'
- Ensure server.port is a positive number
Plugins not loading
Problem: Coralite plugins not recognized
Solutions:
- Verify plugins are imported correctly
- Check that plugins are passed to
defineConfig() - Ensure plugins are compatible with your Coralite version
Performance Issues #
Slow compilation times
Problem: Long wait times for changes to reflect
Solutions:
- Reduce number of files being watched
- Optimize Sass compilation with
silenceDeprecations - Use partials (
_prefix) for Sass files not needed in output - Consider splitting large Sass files
High memory usage
Problem: Development server consuming too much memory
Solutions:
- Restart development server periodically
- Reduce number of files in watched directories
- Check for memory leaks in custom plugins
Common Error Messages #
Error: Configuration must be a valid object
β Ensure you're passing an object to defineConfig()
Error: Configuration must contain a valid "output" property
β Add the required 'output' property to your config
Error: Configuration "server.port" must be a positive number
β Check that server.port is a number greater than 0
Error: Configuration "styles.type" must be equal to either "css", "sass" or "scss"
β Use one of the supported style types
Error: Failed to start server
β Check if port is available and required dependencies are installed
Best Practices #
Development Workflow #
- Use relative paths - Keep all paths relative to project root
- Organize Sass - Use partials for reusable styles
- Monitor logs - Watch terminal for compilation times and errors
- Test frequently - Use live reload to see changes instantly
- Keep public clean - Only include static assets in public directory
Production Builds #
- Clean builds - Always delete output directory before building
- Version control - Don't commit output directory
- Test locally - Run build and test output before deploying
- Optimize assets - Use PostCSS plugins for minification
- Check permissions - Ensure build output has correct permissions
Configuration Management #
- Environment variables - Use different configs for dev/prod if needed
- Version control - Commit coralite.config.js to repository
- Documentation - Comment complex configurations
- Validation - Let defineConfig() catch configuration errors early
Integration with Other Tools #
Git #
Add to .gitignore:
dist/
node_modules/
*.log
VS Code #
Recommended extensions:
- Sass/SCSS syntax highlighting
- HTML/CSS IntelliSense
- ESLint for JavaScript
CI/CD #
Example build script:
npm ci
npm run build
# Deploy dist/ directory
Performance Optimization #
Development #
- Exclude unnecessary files from watching
- Use Sass partials to avoid compiling unused styles
- Limit number of active browser tabs during development
- Restart server if memory usage becomes high
Production #
- Use PostCSS plugins for minification
- Enable Sass compression for production
- Remove source maps for production builds
- Optimize images in public directory
Resources #
- Codeberg: Git repo
- Issues: Git iusses