Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vite-plugin-minify

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-plugin-minify - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

2

dist/index.d.ts

@@ -6,2 +6,2 @@ import { Plugin } from 'vite';

export { ViteMinifyPlugin };
export { ViteMinifyPlugin, ViteMinifyPlugin as default };

@@ -1,2 +0,2 @@

var n=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames,u=Object.getOwnPropertySymbols;var l=Object.prototype.hasOwnProperty,y=Object.prototype.propertyIsEnumerable;var m=(t,e,i)=>e in t?n(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,p=(t,e)=>{for(var i in e||(e={}))l.call(e,i)&&m(t,i,e[i]);if(u)for(var i of u(e))y.call(e,i)&&m(t,i,e[i]);return t};var c=(t,e)=>{for(var i in e)n(t,i,{get:e[i],enumerable:!0})},b=(t,e,i,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of a(e))!l.call(t,r)&&r!==i&&n(t,r,{get:()=>e[r],enumerable:!(o=f(e,r))||o.enumerable});return t};var g=t=>b(n({},"__esModule",{value:!0}),t);var A={};c(A,{ViteMinifyPlugin:()=>v});module.exports=g(A);var s=require("html-minifier-terser");function v(t){return{name:"vite-plugin-minify",enforce:"post",apply:"build",transformIndexHtml:e=>(0,s.minify)(e,p({removeComments:!0,collapseWhitespace:!0,collapseBooleanAttributes:!0,removeAttributeQuotes:!1,removeEmptyAttributes:!0,minifyCSS:!0,minifyJS:!0,minifyURLs:!0},t))}}0&&(module.exports={ViteMinifyPlugin});
var n=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames,m=Object.getOwnPropertySymbols;var c=Object.prototype.hasOwnProperty,w=Object.prototype.propertyIsEnumerable;var s=(t,e,o)=>e in t?n(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,a=(t,e)=>{for(var o in e||(e={}))c.call(e,o)&&s(t,o,e[o]);if(m)for(var o of m(e))w.call(e,o)&&s(t,o,e[o]);return t};var A=(t,e)=>{for(var o in e)n(t,o,{get:e[o],enumerable:!0})},C=(t,e,o,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of h(e))!c.call(t,i)&&i!==o&&n(t,i,{get:()=>e[i],enumerable:!(r=v(e,i))||r.enumerable});return t};var P=t=>C(n({},"__esModule",{value:!0}),t);var S={};A(S,{ViteMinifyPlugin:()=>y,default:()=>R});module.exports=P(S);var p=require("html-minifier-terser"),g=require("path"),d=require("glob"),u=require("fs/promises"),l="vite-plugin-minify";function y(t){let e;return{name:l,enforce:"post",apply:"build",configResolved:o=>{e=o},closeBundle:()=>{(0,d.glob)((0,g.join)(e.build.outDir,"**","*.html"),(o,r)=>{if(o)return console.error(`[${l}]`,o);r.forEach(async i=>{try{let f=await(0,u.readFile)(i,{encoding:"utf-8"}),b=await(0,p.minify)(f.toString(),a({removeComments:!0,collapseWhitespace:!0,collapseBooleanAttributes:!0,removeAttributeQuotes:!1,removeEmptyAttributes:!0,minifyCSS:!0,minifyJS:!0,minifyURLs:!0},t));await(0,u.writeFile)(i,b,"utf-8"),console.log(`[${l}]`,`minified ${i}`)}catch(f){console.error(`[${l}]`,f)}})})}}}var R=y;0&&(module.exports={ViteMinifyPlugin});
//# sourceMappingURL=index.js.map
{
"name": "vite-plugin-minify",
"version": "1.2.0",
"description": "minify html in production",
"version": "1.3.0",
"description": "Minify html in production",
"main": "dist/index.js",

@@ -26,10 +26,15 @@ "module": "dist/index.mjs",

"dependencies": {
"glob": "^8.0.3",
"html-minifier-terser": "^6.1.0"
},
"devDependencies": {
"@types/glob": "^7.2.0",
"@types/html-minifier-terser": "^6.1.0",
"@types/node": "^17.0.36",
"tsup": "^6.0.1",
"vite": "*"
},
"peerDependencies": {
"vite": "^2.9.9"
}
}
# vite-plugin-minify
minify html in production
Minify html in production

@@ -14,3 +14,3 @@ ## Usage

import { defineConfig } from 'vite'
import { ViteMinifyPlugin } from 'vite-plugin-minify'
import minify from 'vite-plugin-minify'

@@ -20,5 +20,5 @@ export default defineConfig({

// input https://www.npmjs.com/package/html-minifier-terser options
ViteMinifyPlugin({}),
minify({}),
],
})
```

@@ -1,20 +0,44 @@

import { Plugin } from 'vite'
import { Plugin, ResolvedConfig } from 'vite'
import { minify, Options } from 'html-minifier-terser'
import { join } from 'path'
import { glob } from 'glob'
import { readFile, writeFile } from 'fs/promises'
const PLUGIN_NAME = 'vite-plugin-minify'
export function ViteMinifyPlugin(options?: Options): Plugin {
let config: ResolvedConfig
return {
name: 'vite-plugin-minify',
name: PLUGIN_NAME,
enforce: 'post',
apply: 'build',
transformIndexHtml: html => {
return minify(html, {
removeComments: true,
collapseWhitespace: true,
collapseBooleanAttributes: true,
removeAttributeQuotes: false,
removeEmptyAttributes: true,
minifyCSS: true,
minifyJS: true,
minifyURLs: true,
...options,
configResolved: resolvedConfig => {
config = resolvedConfig
},
closeBundle: () => {
glob(join(config.build.outDir, '**', '*.html'), (err, files) => {
if (err) {
return console.error(`[${PLUGIN_NAME}]`, err)
}
files.forEach(async file => {
try {
const buffer = await readFile(file, { encoding: 'utf-8' })
const minified = await minify(buffer.toString(), {
removeComments: true,
collapseWhitespace: true,
collapseBooleanAttributes: true,
removeAttributeQuotes: false,
removeEmptyAttributes: true,
minifyCSS: true,
minifyJS: true,
minifyURLs: true,
...options,
})
await writeFile(file, minified, 'utf-8')
console.log(`[${PLUGIN_NAME}]`, `minified ${file}`)
} catch (e) {
console.error(`[${PLUGIN_NAME}]`, e)
}
})
})

@@ -24,1 +48,3 @@ },

}
export default ViteMinifyPlugin

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc