@jsenv/plugin-minification 1.2.2 → 1.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/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@jsenv/plugin-minification",
3
- "version": "1.2.2",
3
+ "version": "1.3.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
7
- "url": "https://github.com/jsenv/jsenv-core",
7
+ "url": "https://github.com/jsenv/core",
8
8
  "directory": "packages/jsenv-plugin-minification"
9
9
  },
10
10
  "publishConfig": {
@@ -25,8 +25,8 @@
25
25
  },
26
26
  "dependencies": {
27
27
  "html-minifier": "4.0.0",
28
- "lightningcss": "1.19.0",
29
- "terser": "5.16.9"
28
+ "lightningcss": "1.20.0",
29
+ "terser": "5.17.5"
30
30
  },
31
31
  "peerDependencies": {
32
32
  "@jsenv/core": "*"
@@ -1,36 +1,36 @@
1
- import { fileURLToPath } from "node:url"
1
+ import { fileURLToPath } from "node:url";
2
2
 
3
3
  export const minifyCss = async ({ cssUrlInfo, context }) => {
4
- const { transform } = await import("lightningcss")
4
+ const { transform } = await import("lightningcss");
5
5
 
6
- const targets = runtimeCompatToTargets(context.runtimeCompat)
6
+ const targets = runtimeCompatToTargets(context.runtimeCompat);
7
7
  const { code, map } = transform({
8
8
  filename: fileURLToPath(cssUrlInfo.originalUrl),
9
9
  code: Buffer.from(cssUrlInfo.content),
10
10
  targets,
11
11
  minify: true,
12
- })
12
+ });
13
13
  return {
14
14
  content: String(code),
15
15
  sourcemap: map,
16
- }
17
- }
16
+ };
17
+ };
18
18
 
19
19
  const runtimeCompatToTargets = (runtimeCompat) => {
20
- const targets = {}
21
- ;["chrome", "firefox", "ie", "opera", "safari"].forEach((runtimeName) => {
22
- const version = runtimeCompat[runtimeName]
20
+ const targets = {};
21
+ ["chrome", "firefox", "ie", "opera", "safari"].forEach((runtimeName) => {
22
+ const version = runtimeCompat[runtimeName];
23
23
  if (version) {
24
- targets[runtimeName] = versionToBits(version)
24
+ targets[runtimeName] = versionToBits(version);
25
25
  }
26
- })
27
- return targets
28
- }
26
+ });
27
+ return targets;
28
+ };
29
29
 
30
30
  const versionToBits = (version) => {
31
31
  const [major, minor = 0, patch = 0] = version
32
32
  .split("-")[0]
33
33
  .split(".")
34
- .map((v) => parseInt(v, 10))
35
- return (major << 16) | (minor << 8) | patch
36
- }
34
+ .map((v) => parseInt(v, 10));
35
+ return (major << 16) | (minor << 8) | patch;
36
+ };
@@ -1,15 +1,28 @@
1
- import { createRequire } from "node:module"
1
+ import { createRequire } from "node:module";
2
2
 
3
3
  // https://github.com/kangax/html-minifier#options-quick-reference
4
4
  export const minifyHtml = ({ htmlUrlInfo, options } = {}) => {
5
- const require = createRequire(import.meta.url)
6
- const { minify } = require("html-minifier")
5
+ const require = createRequire(import.meta.url);
6
+ const { minify } = require("html-minifier");
7
7
 
8
- const { collapseWhitespace = true, removeComments = true } = options
8
+ const {
9
+ // usually HTML will contain a few markup, it's better to keep white spaces
10
+ // and line breaks to favor readability. A few white spaces means very few
11
+ // octets that won't impact performances. Removing whitespaces however will certainly
12
+ // decrease HTML readability
13
+ collapseWhitespace = false,
14
+ // saving a fewline breaks won't hurt performances
15
+ // but will help a lot readability
16
+ preserveLineBreaks = true,
17
+ removeComments = true,
18
+ conservativeCollapse = false,
19
+ } = options;
9
20
 
10
21
  const htmlMinified = minify(htmlUrlInfo.content, {
11
22
  collapseWhitespace,
23
+ conservativeCollapse,
12
24
  removeComments,
13
- })
14
- return htmlMinified
15
- }
25
+ preserveLineBreaks,
26
+ });
27
+ return htmlMinified;
28
+ };
@@ -1,12 +1,12 @@
1
1
  // https://github.com/terser-js/terser#minify-options
2
2
 
3
3
  export const minifyJs = async ({ jsUrlInfo, options }) => {
4
- const url = jsUrlInfo.url
5
- const content = jsUrlInfo.content
6
- const sourcemap = jsUrlInfo.sourcemap
7
- const isJsModule = jsUrlInfo.type === "js_module"
4
+ const url = jsUrlInfo.url;
5
+ const content = jsUrlInfo.content;
6
+ const sourcemap = jsUrlInfo.sourcemap;
7
+ const isJsModule = jsUrlInfo.type === "js_module";
8
8
 
9
- const { minify } = await import("terser")
9
+ const { minify } = await import("terser");
10
10
  const terserResult = await minify(
11
11
  {
12
12
  [url]: content,
@@ -18,14 +18,14 @@ export const minifyJs = async ({ jsUrlInfo, options }) => {
18
18
  includeSources: true,
19
19
  },
20
20
  module: isJsModule,
21
- // We need to preserve "new InlineContent()" calls to be able to recognize them
21
+ // We need to preserve "new __InlineContent__()" calls to be able to recognize them
22
22
  // after minification in order to version urls inside inline content text
23
- keep_fnames: /InlineContent/,
23
+ keep_fnames: /__InlineContent__/,
24
24
  ...options,
25
25
  },
26
- )
26
+ );
27
27
  return {
28
28
  content: terserResult.code,
29
29
  sourcemap: terserResult.map,
30
- }
31
- }
30
+ };
31
+ };
@@ -1,7 +1,7 @@
1
- import { minifyHtml } from "./html/html_minification.js"
2
- import { minifyCss } from "./css/css_minification.js"
3
- import { minifyJs } from "./js/js_minification.js"
4
- import { minifyJson } from "./json/json_minification.js"
1
+ import { minifyHtml } from "./html/html_minification.js";
2
+ import { minifyCss } from "./css/css_minification.js";
3
+ import { minifyJs } from "./js/js_minification.js";
4
+ import { minifyJson } from "./json/json_minification.js";
5
5
 
6
6
  export const jsenvPluginMinification = ({
7
7
  html = {},
@@ -18,7 +18,7 @@ export const jsenvPluginMinification = ({
18
18
  context,
19
19
  options: html === true ? {} : html,
20
20
  })
21
- : null
21
+ : null;
22
22
  const svgMinifier = svg
23
23
  ? (urlInfo, context) =>
24
24
  minifyHtml({
@@ -26,7 +26,7 @@ export const jsenvPluginMinification = ({
26
26
  context,
27
27
  options: svg === true ? {} : svg,
28
28
  })
29
- : null
29
+ : null;
30
30
  const cssMinifier = css
31
31
  ? (urlInfo, context) =>
32
32
  minifyCss({
@@ -34,7 +34,7 @@ export const jsenvPluginMinification = ({
34
34
  context,
35
35
  options: css === true ? {} : css,
36
36
  })
37
- : null
37
+ : null;
38
38
  const jsClassicMinifier = js_classic
39
39
  ? (urlInfo, context) =>
40
40
  minifyJs({
@@ -42,7 +42,7 @@ export const jsenvPluginMinification = ({
42
42
  context,
43
43
  options: js_classic === true ? {} : js_classic,
44
44
  })
45
- : null
45
+ : null;
46
46
  const jsModuleMinifier = js_module
47
47
  ? (urlInfo, context) =>
48
48
  minifyJs({
@@ -50,7 +50,7 @@ export const jsenvPluginMinification = ({
50
50
  context,
51
51
  options: js_module === true ? {} : js_module,
52
52
  })
53
- : null
53
+ : null;
54
54
  const jsonMinifier = json
55
55
  ? (urlInfo, context) =>
56
56
  minifyJson({
@@ -58,7 +58,7 @@ export const jsenvPluginMinification = ({
58
58
  context,
59
59
  options: json === true ? {} : html,
60
60
  })
61
- : null
61
+ : null;
62
62
 
63
63
  return {
64
64
  name: "jsenv:minification",
@@ -73,5 +73,5 @@ export const jsenvPluginMinification = ({
73
73
  importmap: jsonMinifier,
74
74
  webmanifest: jsonMinifier,
75
75
  },
76
- }
77
- }
76
+ };
77
+ };
@@ -1,8 +1,8 @@
1
1
  export const minifyJson = ({ jsonUrlInfo }) => {
2
- const { content } = jsonUrlInfo
2
+ const { content } = jsonUrlInfo;
3
3
  if (content.startsWith("{\n")) {
4
- const jsonWithoutWhitespaces = JSON.stringify(JSON.parse(content))
5
- return jsonWithoutWhitespaces
4
+ const jsonWithoutWhitespaces = JSON.stringify(JSON.parse(content));
5
+ return jsonWithoutWhitespaces;
6
6
  }
7
- return null
8
- }
7
+ return null;
8
+ };
package/src/main.js CHANGED
@@ -1 +1 @@
1
- export { jsenvPluginMinification } from "./jsenv_plugin_minification.js"
1
+ export { jsenvPluginMinification } from "./jsenv_plugin_minification.js";