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

babel-plugin-template-html-minifier

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-template-html-minifier - npm Package Compare versions

Comparing version 3.0.2 to 3.1.0

9

CHANGELOG.md

@@ -5,2 +5,11 @@ # Changelog

## [3.1.0](https://github.com/cfware/babel-plugin-template-html-minifier/compare/v3.0.2...v3.1.0) (2019-07-24)
### Features
* Configurable html-minifier error handling ([#34](https://github.com/cfware/babel-plugin-template-html-minifier/issues/34)) ([d1f4c06](https://github.com/cfware/babel-plugin-template-html-minifier/commit/d1f4c06))
### [3.0.2](https://github.com/cfware/babel-plugin-template-html-minifier/compare/v3.0.1...v3.0.2) (2019-07-14)

@@ -7,0 +16,0 @@

37

lib/index.js

@@ -70,17 +70,30 @@ 'use strict';

const tags = encapsulationGetTags(bindingOptions);
let parts;
const minified = htmlMinifier.minify(tags.opening + quasis.join(placeholder) + tags.closing, state.opts.htmlMinifier);
if (!minified.startsWith(tags.opening) || !minified.endsWith(tags.closing)) {
throw path.buildCodeFrameError(majorDeleteError);
try {
const minified = htmlMinifier.minify(tags.opening + quasis.join(placeholder) + tags.closing, state.opts.htmlMinifier);
if (!minified.startsWith(tags.opening) || !minified.endsWith(tags.closing)) {
throw path.buildCodeFrameError(majorDeleteError);
}
const minifiedParts = minified.slice(tags.opening.length, -tags.closing.length || undefined).split(placeholder);
if (minifiedParts.length !== quasis.length) {
throw path.buildCodeFrameError(majorDeleteError);
}
parts = minifiedParts;
} catch (error) {
if (state.failOnError) {
throw error;
} else if (state.logOnError) {
console.error(error.message);
}
}
const parts = minified.slice(tags.opening.length, -tags.closing.length || undefined).split(placeholder);
if (parts.length !== quasis.length) {
throw path.buildCodeFrameError(majorDeleteError);
if (parts) {
parts.forEach((raw, i) => {
const args = cookRawQuasi(state.babel, raw);
template.get('quasis')[i].replaceWith(t.templateElement(args, i === parts.length - 1));
});
}
parts.forEach((raw, i) => {
const args = cookRawQuasi(state.babel, raw);
template.get('quasis')[i].replaceWith(t.templateElement(args, i === parts.length - 1));
});
}

@@ -141,2 +154,4 @@

this.moduleConfigs = normalizeModulesConfig(this.opts.modules);
this.failOnError = this.opts.failOnError !== false;
this.logOnError = this.opts.logOnError !== false;
this.babel = babel;

@@ -143,0 +158,0 @@ this.bindings = [];

{
"name": "babel-plugin-template-html-minifier",
"description": "Minify HTML in tagged template strings using html-minifier",
"version": "3.0.2",
"version": "3.1.0",
"main": "lib/index.js",

@@ -6,0 +6,0 @@ "scripts": {

@@ -92,2 +92,15 @@ # babel-plugin-template-html-minifier

### failOnError
Determines whether an error should be thrown when minification failed. defaults to true.
Minification can fail when using invalid syntax or comments within bindings. Especially
when using css with bindings minification can fail. When `failOnError` is true, this
plugin throws an error and your build will stop from proceeding. When it is false
the minification is canceled and the template is left unminified.
### logOnError
Determines whether failure to minify a template should be logged in case of an error.
Defaults to true.
```js

@@ -94,0 +107,0 @@ import choo from 'choo/html';

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