Sarcina Web Project Bundler

1.7.6 · active · verified Tue Apr 21

Sarcina is a fully-automatic, zero-configuration web project bundler designed to prepare vanilla, non-framework web projects for production. It offers a simpler, faster alternative to complex bundlers like Webpack, specifically targeting projects that do not require constant re-building during development. Instead, Sarcina is intended for a single run prior to deployment. The current stable version is 1.7.6. Sarcina processes markup files, identifies CSS and JavaScript assets, creates optimized bundles, and re-inserts links to these new bundles. During this process, it minifies HTML, minifies and autoprefixes CSS, and minifies and transpiles JavaScript. This results in a distribution folder with fewer, smaller, and less complex files, significantly improving browser load times and user experience. Its primary differentiator is its "works-out-of-the-box" philosophy, eliminating the need for extensive configuration often associated with other bundlers.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates programmatic usage of Sarcina to bundle a simple vanilla web project. It creates a source directory with HTML, CSS, and JavaScript files, then invokes the 'sarcina' function with input and output paths to generate an optimized 'dist' folder. It requires Node.js (with ESM support for this specific example) and 'sarcina' installed.

import sarcina from 'sarcina';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
import { mkdir, writeFile, rm } from 'fs/promises';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

async function setupAndBundle() {
    const srcDir = join(__dirname, 'src');
    const distDir = join(__dirname, 'dist');
    const cssDir = join(srcDir, 'css');
    const jsDir = join(srcDir, 'js');

    // Clean up previous runs and set up source directories
    await rm(distDir, { recursive: true, force: true });
    await rm(srcDir, { recursive: true, force: true });
    await mkdir(cssDir, { recursive: true });
    await mkdir(jsDir, { recursive: true });

    // Create sample HTML, CSS, and JS files
    await writeFile(join(srcDir, 'index.html'), `
        <!DOCTYPE html>
        <html>
            <head>
                <title>Sarcina Demo</title>
                <link rel="stylesheet" href="css/base.css">
            </head>
            <body>
                <h1>Hello Sarcina!</h1>
                <script src="js/main.js"></script>
            </body>
        </html>
    `);

    await writeFile(join(cssDir, 'base.css'), `
        body {\n            font-family: sans-serif;\n            background-color: #f0f0f0;\n            color: #333;\n        }\n        h1 {\n            text-align: center;\n            color: #007bff;\n        }
    `);

    await writeFile(join(jsDir, 'main.js'), `
        console.log("Sarcina has bundled this page!");
        document.addEventListener('DOMContentLoaded', () => {
            const heading = document.querySelector('h1');
            if (heading) {
                heading.textContent += ' (Bundled!)';
            }
        });
    `);

    console.log('Sample project created in ./src. Running Sarcina...');

    try {
        // Programmatic API: Assuming a default export function that takes an options object.
        // The `input` and `output` properties are inferred from common bundler patterns
        // and the package's description of processing 'markup files in a folder'.
        await sarcina({
            input: srcDir,
            output: distDir
        });
        console.log(`Bundling complete! Check '${distDir}' for results.`);
    } catch (error) {
        console.error('Sarcina bundling failed:', error);
    }
}

setupAndBundle();

view raw JSON →