vite-plugin-minify
Advanced tools
Comparing version 1.2.0 to 1.3.0
@@ -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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13240
81
3
5
2
+ Addedglob@^8.0.3
+ Added@esbuild/linux-loong64@0.14.54(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@2.0.1(transitive)
+ Addedesbuild@0.14.54(transitive)
+ Addedesbuild-android-64@0.14.54(transitive)
+ Addedesbuild-android-arm64@0.14.54(transitive)
+ Addedesbuild-darwin-64@0.14.54(transitive)
+ Addedesbuild-darwin-arm64@0.14.54(transitive)
+ Addedesbuild-freebsd-64@0.14.54(transitive)
+ Addedesbuild-freebsd-arm64@0.14.54(transitive)
+ Addedesbuild-linux-32@0.14.54(transitive)
+ Addedesbuild-linux-64@0.14.54(transitive)
+ Addedesbuild-linux-arm@0.14.54(transitive)
+ Addedesbuild-linux-arm64@0.14.54(transitive)
+ Addedesbuild-linux-mips64le@0.14.54(transitive)
+ Addedesbuild-linux-ppc64le@0.14.54(transitive)
+ Addedesbuild-linux-riscv64@0.14.54(transitive)
+ Addedesbuild-linux-s390x@0.14.54(transitive)
+ Addedesbuild-netbsd-64@0.14.54(transitive)
+ Addedesbuild-openbsd-64@0.14.54(transitive)
+ Addedesbuild-sunos-64@0.14.54(transitive)
+ Addedesbuild-windows-32@0.14.54(transitive)
+ Addedesbuild-windows-64@0.14.54(transitive)
+ Addedesbuild-windows-arm64@0.14.54(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedfsevents@2.3.3(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedglob@8.1.0(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedis-core-module@2.15.1(transitive)
+ Addedminimatch@5.1.6(transitive)
+ Addednanoid@3.3.8(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpath-parse@1.0.7(transitive)
+ Addedpicocolors@1.1.1(transitive)
+ Addedpostcss@8.4.49(transitive)
+ Addedresolve@1.22.8(transitive)
+ Addedrollup@2.77.3(transitive)
+ Addedsource-map-js@1.2.1(transitive)
+ Addedsupports-preserve-symlinks-flag@1.0.0(transitive)
+ Addedvite@2.9.18(transitive)
+ Addedwrappy@1.0.2(transitive)