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.
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
minier build
import minier from "minier";
minier({
baseDir: "src/",
outDir: "release/"
/* ... */
});
-
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.
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.
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/"
}
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/"
}
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"
]
}
Clear the output folder before exporting.
Boolean
config.cleanOutDir || false
{
"cleanOutDir": true
}
Compress the <style>
tag at the same time.
Boolean
config.html.minifyCSS || true
{
"html": {
"minifyCSS": false
}
}
Compress the <script>
tag at the same time.
Boolean
config.html.minifyJS || true
{
"html": {
"minifyJS": false
}
}
Inline styles in style=""
are no longer compressed.
Boolean
config.html.noMinifyInlineStyles || true
{
"html": {
"noMinifyInlineStyles": false
}
}
Remove two consecutive spaces in JavaScript.
Boolean
config.js.noSpaces || false
- Relatively aggressive configuration items.
{
js: {
noSpaces: true
}
}
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
}
}
This affects <style> tags and .css files.
{
cleanCSS: {
level: 1,
compatibility: "*",
format: false,
inline: false,
...config.cleanCSS
}
}
terser.compress
This affects <script> tags, .js, .cjs, and .mjs files.
{
terser: {
compress: {
dead_code: true,
drop_console: false,
...config.terser.compress
}
}
}
This affects .svg and .xml files.
{
xmlMinify: {
removeComments: true,
removeWhitespaceBetweenTags: true,
...config.xmlMinify
}
}