@localnerve/web-component-build 0.2.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -12,7 +12,9 @@ The following is a table of _some_ of the possible input, processing, and output
12
12
 
13
13
  | input | processing | output |
14
14
  | ----- | ---------- | ------ |
15
- | javascript | minify or optional pass-thru | javascript |
15
+ | javascript | minify javascript | javascript |
16
+ | css | minify css | css |
17
+ | html | minify html | html |
16
18
  | css, html | minify css, prepend style tag to html, minify html | css, html |
17
19
  | css, html, cssHref | minfy css, prepend style tag to html, prepend link tag to html, minify html | css, html |
18
20
  | cssHref, html | prepend link tag to html, minify html | html |
@@ -80,7 +82,7 @@ One or more of `cssPath`, `jsPath`, and/or `htmlPath` **must** be supplied. They
80
82
  + cssLinkHref will be prepended in a `link` tag
81
83
  + html will be inserted into the javascript file if `jsReplacement` and `jsPath` is supplied
82
84
  * `jsPath` {String} - Full path to the input javascript file
83
- * `jsReplacement` {String} - The token to replace with the css or html in the javascript file
85
+ * `jsReplacement` {String|RegExp} - The replacement pattern for the css or html in the javascript file. See [pattern](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#pattern) for full documentation
84
86
  If supplied:
85
87
  + A replacement will be attempted in the javascript file
86
88
  + If **not supplied** or falsy, No replacement will be attempted and all assets are just copied to `outputDir`
package/lib/build.js CHANGED
@@ -11,6 +11,14 @@ import CleanCss from 'clean-css';
11
11
  import {minify as _minifyHtml} from 'html-minifier';
12
12
  import {minify as _minifyJs} from 'terser';
13
13
 
14
+ export const defaultHtmlMinifyOptions = {
15
+ minifyJS: true,
16
+ minifyCSS: true,
17
+ collapseWhitespace: true,
18
+ removeAttributeQuotes: true,
19
+ removeComments: true
20
+ };
21
+
14
22
  class WebComponentBuild {
15
23
 
16
24
  /**
@@ -77,13 +85,7 @@ class WebComponentBuild {
77
85
  * @param {Object} options - The html-minifier options.
78
86
  * @returns {String} minified html.
79
87
  */
80
- async minifyHtml (htmlText, options = {
81
- minifyJS: true,
82
- minifyCSS: true,
83
- collapseWhitespace: true,
84
- removeAttributeQuotes: true,
85
- removeComments: true
86
- }) {
88
+ async minifyHtml (htmlText, options = defaultHtmlMinifyOptions) {
87
89
  const minifiedHtml =
88
90
  this.minifySkip ? htmlText : _minifyHtml(htmlText, options);
89
91
 
package/lib/index.js CHANGED
@@ -8,17 +8,10 @@
8
8
  */
9
9
  import * as fs from 'node:fs/promises';
10
10
  import * as cheerio from 'cheerio';
11
- import {createBuild} from './build.js';
11
+ import {createBuild, defaultHtmlMinifyOptions} from './build.js';
12
12
 
13
13
  /**
14
14
  * Build entry point.
15
- * Possible build outcomes:
16
- * 1. jsFile only - all contained. Don't expose any css/html to build. Minify js only.
17
- * 2. css in js - replace the inline css in js. expose the css to build.
18
- * 3. css in html - add the inline css to html, replace the html in the js, expose css/html to build.
19
- * 4. csslink in html - add the css link to html, replace the html in the js, expose css/html to build.
20
- * 5. csslink in js - add the css link to js, replace the html in js.
21
- * 6. html in js - replace the html in the js, expose html to build.
22
15
  *
23
16
  * @param {String} outputDir - full path to the output directory
24
17
  * @param {Object} [options] - optional options
@@ -60,6 +53,8 @@ export async function build (outputDir, {
60
53
  const $ = cheerio.load(htmlText);
61
54
  if (cssText) {
62
55
  $('body').prepend(`<style>${cssText}</style>`);
56
+ htmlminOptions = htmlminOptions || defaultHtmlMinifyOptions;
57
+ htmlminOptions.minifyCSS = cleancssOptions;
63
58
  }
64
59
  if (cssLinkHref) {
65
60
  $('body').prepend(`<link href="${cssLinkHref}" rel="stylesheet" />`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@localnerve/web-component-build",
3
- "version": "0.2.3",
3
+ "version": "0.3.0",
4
4
  "description": "A library to help build web components",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -57,6 +57,9 @@
57
57
  "jest": "^29.7.0",
58
58
  "tempy": "^3.1.0"
59
59
  },
60
+ "overrides": {
61
+ "clean-css": "$clean-css"
62
+ },
60
63
  "engines": {
61
64
  "node": ">=18"
62
65
  }