Deno.js WASM Source Code Minifier or Compressor Module Tutorial to Compress HTML,CSS,JSON,JS Code in TypeScript Full Project For Beginners

 

minifier

 

An awesome language minifier for Deno that is powered by WebAssembly!

 

 

 

Usage

 

 

 

To start using minifier with Deno, just add an import to the top of your file and get all of the features that you want to use from there! Here is an example import:

 

 

 

import { Language, minify } from "https://deno.land/x/minifier/mod.ts";

 

 

const code = `
html {
  margin: 0;
  padding: 0;
}`;

minify(Language.CSS, code);

 

 

 

Minifying Code

 

 

 

const code = `
html {
  margin: 0;
  padding: 0;
}`;

// both return the minifed CSS
minify(Language.CSS, code);
minify("css", code);

 

 

Minifying HTML

 

 

const code = `
<html>
<head>
  <style>
    html {
      margin: 0;
      padding: 0;
    }
  </style>
  <script>
    const x = 23;
    if (x > 20) {
      x--;
    }
    console.log(x);
  </script>
</head>
</html>
`;

// returns the minified HTML code with the CSS and JS code properly minified, too
minifyHTML(code, {
  minifyCSS: true,
  minifyJS: true,
});

 

 

CLI

Minifier even has its own CLI that allows you quickly minify files in your terminal.

See also  jsPDF Html2Canvas PDF Certificate Generator Project in Javascript Full Tutorial For Beginners

Installation

To install the CLI for minifier, run the following command:

deno install --allow-read --allow-write --allow-hrtime https://deno.land/x/minifier/cli.ts

We strongly suggest including the --allow-hrtime flag as it allows the performance benchmarks to be more accurate.

Commands

Command Action
<file-location> minifies the given file from the location specified
<file-location> <output-location> minifies the given file from the file location and saves it as the output file
-H--help provides info on all of the commands available
-V--version gives the version info for the CLI

 

Leave a Reply