vite-plugin-html-env
Advanced tools
Comparing version 1.2.3 to 1.2.4
@@ -97,3 +97,4 @@ "use strict"; | ||
compiler: true, | ||
enforce: null | ||
enforce: null, | ||
compress: false | ||
}; | ||
@@ -110,3 +111,4 @@ | ||
compiler = _pick2.compiler, | ||
enforce = _pick2.enforce; | ||
enforce = _pick2.enforce, | ||
compress = _pick2.compress; | ||
@@ -133,3 +135,4 @@ let transformIndexHtml = { | ||
prefix, | ||
suffix | ||
suffix, | ||
compress | ||
})); | ||
@@ -136,0 +139,0 @@ parseHtml.parse(); |
@@ -114,6 +114,2 @@ "use strict"; | ||
this.html = this.html.replace(/[ ]+/g, ' '); | ||
this.html = this.html.replace(/<[\s]+/g, '<'); | ||
this.html = this.html.replace(/[\s]+</g, '<'); | ||
this.html = this.html.replace(/[\s]+>/g, '>'); | ||
this.html = this.html.replace(/[\s]+\/>/g, '/>'); | ||
this.html = this.html.replace(/[\s]*=[\s]*"/g, '="'); | ||
@@ -126,2 +122,6 @@ let _this$options = this.options, | ||
this.html = this.html.replace(/import\.meta\.env\.([a-zA-Z_\-]+)/g, (...arg) => `${this.options[arg[1]] || ''}`); | ||
this.html = this.html.replace(/<[\s]+/g, '<'); | ||
this.html = this.html.replace(/[\s]+</g, '<'); | ||
this.html = this.html.replace(/[\s]+>/g, '>'); | ||
this.html = this.html.replace(/[\s]+\/>/g, '/>'); | ||
} | ||
@@ -434,3 +434,3 @@ | ||
html += Array.from({ | ||
length: depth | ||
length: depth - 1 | ||
}).fill('\t').join(''); | ||
@@ -444,3 +444,3 @@ } | ||
html += Array.from({ | ||
length: depth | ||
length: depth - 1 | ||
}).fill('\t').join(''); | ||
@@ -471,3 +471,3 @@ | ||
if (CLOSE_TAG_MAP[tag]) return; | ||
const length = text || children.length === 0 ? 0 : depth; | ||
const length = text || children.length === 0 ? 0 : depth - 1; | ||
@@ -488,3 +488,16 @@ if (!this.checkOnlyOneTextNode(tree)) { | ||
} | ||
}); | ||
}); // Simple compression: | ||
// remove spaces and line breaks | ||
if (this.options.compress) { | ||
html = html.replace(/\n[ ]+/g, ' '); | ||
html = html.replace(/\n/g, ''); | ||
html = html.replace(/[ ]+/g, ' '); | ||
html = html.replace(/[\s]*=[\s]*"/g, '="'); | ||
html = html.replace(/<[\s]+/g, '<'); | ||
html = html.replace(/[\s]+</g, '<'); | ||
html = html.replace(/[\s]+>/g, '>'); | ||
html = html.replace(/[\s]+\/>/g, '/>'); | ||
} | ||
return html; | ||
@@ -491,0 +504,0 @@ } |
{ | ||
"name": "vite-plugin-html-env", | ||
"version": "1.2.3", | ||
"version": "1.2.4", | ||
"description": "A vite plugin for rewriting html", | ||
@@ -5,0 +5,0 @@ "files": [ |
@@ -140,1 +140,12 @@ # vite-plugin-html-env [](https://npmjs.com/package/vite-plugin-html-env) | ||
The new version of the plugin is enabled by default, and the template compilation mode is added, which contains new directives `vite-if` and `vite-else`, new parsing rules `import.meta.env.VITE_APP_***`. | ||
### `enforce` | ||
- **Type:** `string` | ||
- **Default:** `null` | ||
The value of enforce can be either "pre" or "post". [plugin-ordering](https://vitejs.dev/guide/api-plugin.html#plugin-ordering]) | ||
### `compress` | ||
- **Type:** `boolean` | ||
- **Default:** `false` | ||
Simple compression: remove spaces and line breaks |
@@ -84,3 +84,4 @@ const { loadEnv } = require('vite') | ||
compiler: true, | ||
enforce: null | ||
enforce: null, | ||
compress: false | ||
} | ||
@@ -91,3 +92,3 @@ | ||
config = config || {} | ||
let { prefix, suffix, envPrefixes, compiler, enforce } = _pick(config, DEFAULT_CONFIG) | ||
let { prefix, suffix, envPrefixes, compiler, enforce, compress } = _pick(config, DEFAULT_CONFIG) | ||
@@ -114,3 +115,4 @@ let transformIndexHtml = { | ||
prefix, | ||
suffix | ||
suffix, | ||
compress | ||
}) | ||
@@ -117,0 +119,0 @@ |
@@ -84,6 +84,3 @@ const { removeComments } = require("../utils") | ||
this.html = this.html.replace(/[ ]+/g, ' ') | ||
this.html = this.html.replace(/<[\s]+/g, '<') | ||
this.html = this.html.replace(/[\s]+</g, '<') | ||
this.html = this.html.replace(/[\s]+>/g, '>') | ||
this.html = this.html.replace(/[\s]+\/>/g, '/>') | ||
this.html = this.html.replace(/[\s]*=[\s]*"/g, '="') | ||
@@ -97,2 +94,7 @@ | ||
this.html = this.html.replace(/import\.meta\.env\.([a-zA-Z_\-]+)/g, (...arg) => `${this.options[arg[1]] || ''}`) | ||
this.html = this.html.replace(/<[\s]+/g, '<') | ||
this.html = this.html.replace(/[\s]+</g, '<') | ||
this.html = this.html.replace(/[\s]+>/g, '>') | ||
this.html = this.html.replace(/[\s]+\/>/g, '/>') | ||
} | ||
@@ -376,3 +378,3 @@ | ||
if (!this.checkOnlyOneTextNode(parent)) { | ||
html += Array.from({ length: depth }).fill('\t').join('') | ||
html += Array.from({ length: depth - 1 }).fill('\t').join('') | ||
} | ||
@@ -382,4 +384,5 @@ html += text | ||
} | ||
html += Array.from({ length: depth }).fill('\t').join('') | ||
html += Array.from({ length: depth - 1 }).fill('\t').join('') | ||
if (CLOSE_TAG_MAP[tag]) { | ||
@@ -405,3 +408,3 @@ html += `<${tag}${attributeText}/>\n` | ||
const length = text || children.length === 0 ? 0 : depth | ||
const length = text || children.length === 0 ? 0 : depth - 1 | ||
@@ -422,2 +425,15 @@ if (!this.checkOnlyOneTextNode(tree)) { | ||
// Simple compression: | ||
// remove spaces and line breaks | ||
if (this.options.compress) { | ||
html = html.replace(/\n[ ]+/g, ' ') | ||
html = html.replace(/\n/g, '') | ||
html = html.replace(/[ ]+/g, ' ') | ||
html = html.replace(/[\s]*=[\s]*"/g, '="') | ||
html = html.replace(/<[\s]+/g, '<') | ||
html = html.replace(/[\s]+</g, '<') | ||
html = html.replace(/[\s]+>/g, '>') | ||
html = html.replace(/[\s]+\/>/g, '/>') | ||
} | ||
return html | ||
@@ -424,0 +440,0 @@ } |
43802
1119
151