minier
TypeScript icon, indicating that this package has built-in type declarations

1.3.1 • Public • Published

minier - Automatic static file compressor

minier is an automated source code minimization compressor with zero configuration available. It behaves like a JavaScript ESM packager, but maintains the file structure and path of the development directory in the output directory.

Installation

npm install -D minier@latest

Or use a global installation, which will get the input/output directories for the minier.config.json and relative paths from the directory where the minier command was run.

npm install -g minier@latest

Build commands

minier build

Use ESM

import minier from "minier";

minier({
    baseDir: "src/",
    outDir: "release/"
    /* ... */
});

Default behavior

  • Silently takes files from the src/ directory and compresses them and outputs them to the release/ directory.

  • Supports .html / .htm / .css / .js / .mjs / .cjs / .json / .xml / .svg files.

Configuration

When baseDir and outDir are the same, minier will create a temporary directory as outDir, and the temporary directory will be deleted immediately after the mission is completed, and the files in the baseDir will be overwritten.

Whether in minier.config.json or in the way ESM is used, their configuration items are consistent.

outDir

Specify the output directory. It can also be specified from the -o or --output of the CLI.

String config.outDir || "release/"

{
    "outDir": "example-output-folder/"
}

baseDir

Specify the input directory from which the files that need to be processed before compression will be read. It can also be specified from the -i or --input of the CLI.

String config.baseDir || "src/"

{
    "baseDir": "example-input-folder/"
}

ignore

Based on baseDir ignores directories or files, does not count towards the total number of files, and is copied directly to the output directory.

Array config.ignorePaths || []

{
    "ignorePaths": [
        "node_modules/**",
        "dir/**",
        "sub/dir/**",
        "**/*.mjs"
    ]
}

cleanOutDir

Clear the output folder before exporting.

Boolean config.cleanOutDir || false

{
    "cleanOutDir": true
}

html.minifyCSS

Compress the <style> tag at the same time.

Boolean config.html.minifyCSS || true

{
    "html": {
        "minifyCSS": false
    }
}

html.minifyJS

Compress the <script> tag at the same time.

Boolean config.html.minifyJS || true

{
    "html": {
        "minifyJS": false
    }
}

html.noMinifyInlineStyles

Inline styles in style="" are no longer compressed.

Boolean config.html.noMinifyInlineStyles || true

{
    "html": {
        "noMinifyInlineStyles": false
    }
}

js.noSpaces

Remove two consecutive spaces in JavaScript.

Boolean config.js.noSpaces || false

  • Relatively aggressive configuration items.
{
    js: {
        noSpaces: true
    }
}

Configure inheritance

htmlTerser

html-minifier-terser

This affects .html and .htm files.

{
    htmlTerser: {
        caseSensitive: true,
        collapseBooleanAttributes: true,
        collapseWhitespace: true,
        conservativeCollapse: false,
        decodeEntities: false,
        html5: true,
        removeComments: true,
        removeEmptyAttributes: true,
        removeScriptTypeAttributes: false,
        removeStyleLinkTypeAttributes: false,
        keepClosingSlash: true,
        ...config.htmlTerser
    }
}

cleanCSS

CleanCSS

This affects <style> tags and .css files.

{
    cleanCSS: {
        level: 1,
        compatibility: "*",
        format: false,
        inline: false,
        ...config.cleanCSS
    }
}

terser

terser.compress

This affects <script> tags, .js, .cjs, and .mjs files.

{
    terser: {
        compress: {
            dead_code: true,
            drop_console: false,
            ...config.terser.compress
        }
    }
}

xmlMinify

minify-xml

This affects .svg and .xml files.

{
    xmlMinify: {
        removeComments: true,
        removeWhitespaceBetweenTags: true,
        ...config.xmlMinify
    }
}

Package Sidebar

Install

npm i minier

Weekly Downloads

3

Version

1.3.1

License

MIT

Unpacked Size

15.8 kB

Total Files

9

Last publish

Collaborators

  • zeoseven