@localnerve/web-component-build 0.2.4 → 0.3.1
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/lib/build.js +9 -7
- package/lib/index.js +3 -8
- package/package.json +4 -1
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.
|
|
3
|
+
"version": "0.3.1",
|
|
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
|
}
|