mowdown: HTML, CSS, and JS Production Bundler

2.2.2 · active · verified Tue Apr 21

Mowdown is a lightweight, standalone JavaScript bundler designed for straightforward production preparation of web applications. Currently at version 2.2.2, it provides a minimal approach to consolidating and optimizing HTML, CSS, and JavaScript assets without requiring complex build configurations or a persistent local server process. The tool operates by scanning specified HTML files, identifying local CSS and JavaScript references (via `<link>` and `<script>` tags), and then concatenating, minifying, and optionally applying Babel transformations to these assets. Its primary differentiator is its simplicity and "no build step" philosophy, aiming to reduce developer overhead by working directly with existing HTML structures rather than introducing module systems or advanced optimizations like tree shaking or code splitting. It is suitable for projects where the build process needs to be minimal and predictable, especially for static sites or simple web applications. It operates purely as a Node.js utility.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `mowdown` to bundle and minify HTML, CSS, and JavaScript files from a source directory into an output directory. It creates temporary input files and a minimal `.babelrc` (which mowdown requires), then processes them and cleans up, showcasing basic API usage with options like `sourceFolder` and `isOverwritingHtml`.

const mowdown = require('mowdown');
const fs = require('fs');
const path = require('path');

// Create temporary input and output directories
const inputDir = path.join(__dirname, 'temp_mowdown_input');
const outputDir = path.join(__dirname, 'temp_mowdown_output');
fs.mkdirSync(inputDir, { recursive: true });
fs.mkdirSync(outputDir, { recursive: true });

// Create dummy HTML, CSS, JS files for bundling
const htmlContent = `<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Mowdown Test</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <h1>Welcome to Mowdown!</h1>
    <script src="script.js"></script>
</body>
</html>`;
const cssContent = `body { font-family: 'Arial', sans-serif; background-color: #e0f2f7; } h1 { color: #0277bd; text-align: center; }`;
const jsContent = `document.addEventListener('DOMContentLoaded', () => {
    console.log('JavaScript processed by mowdown!');
    const heading = document.querySelector('h1');
    if (heading) heading.textContent = 'Mowdown has bundled this content!';
});`;

fs.writeFileSync(path.join(inputDir, 'index.html'), htmlContent);
fs.writeFileSync(path.join(inputDir, 'style.css'), cssContent);
fs.writeFileSync(path.join(inputDir, 'script.js'), jsContent);

// Define a minimal .babelrc required by mowdown
const babelrcContent = `{ "presets": ["@babel/preset-env"] }`;
fs.writeFileSync(path.join(__dirname, '.babelrc'), babelrcContent);

async function runBundler() {
    try {
        console.log('Running mowdown bundling process...');
        await mowdown([path.join(inputDir, 'index.html')], outputDir, {
            sourceFolder: inputDir,
            isOverwritingHtml: false // Crucial to avoid overwriting original source HTML
        });
        console.log(`
✅ Mowdown finished successfully. Check '${outputDir}' for bundled files.`);
        
        // Optional: Verify bundled HTML content
        const bundledHtmlPath = path.join(outputDir, 'index.html');
        if (fs.existsSync(bundledHtmlPath)) {
            const bundledHtmlSnippet = fs.readFileSync(bundledHtmlPath, 'utf-8').substring(0, 500) + '...';
            console.log('\nBundled index.html snippet:\n', bundledHtmlSnippet);
        }
    } catch (error) {
        console.error('\n❌ Mowdown failed:', error.message);
    } finally {
        // Clean up temporary files and directories
        fs.rmSync(inputDir, { recursive: true, force: true });
        fs.rmSync(outputDir, { recursive: true, force: true });
        fs.rmSync(path.join(__dirname, '.babelrc'), { force: true });
        console.log('\nCleaned up temporary files and directories.');
    }
}

runBundler();

view raw JSON →