@jsenv/plugin-minification 1.0.2 → 1.2.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,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/plugin-minification",
3
- "version": "1.0.2",
3
+ "version": "1.2.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -24,8 +24,8 @@
24
24
  "test": "node --conditions=development ./scripts/test.mjs"
25
25
  },
26
26
  "dependencies": {
27
- "@jsenv/ast": "1.4.10",
28
27
  "html-minifier": "4.0.0",
28
+ "lightningcss": "1.18.0",
29
29
  "terser": "5.16.1"
30
30
  },
31
31
  "peerDependencies": {
@@ -0,0 +1,36 @@
1
+ import { fileURLToPath } from "node:url"
2
+
3
+ export const minifyCss = async ({ cssUrlInfo, context }) => {
4
+ const { transform } = await import("lightningcss")
5
+
6
+ const targets = runtimeCompatToTargets(context.runtimeCompat)
7
+ const { code, map } = transform({
8
+ filename: fileURLToPath(cssUrlInfo.originalUrl),
9
+ code: Buffer.from(cssUrlInfo.content),
10
+ targets,
11
+ minify: true,
12
+ })
13
+ return {
14
+ content: String(code),
15
+ sourcemap: map,
16
+ }
17
+ }
18
+
19
+ const runtimeCompatToTargets = (runtimeCompat) => {
20
+ const targets = {}
21
+ ;["chrome", "firefox", "ie", "opera", "safari"].forEach((runtimeName) => {
22
+ const version = runtimeCompat[runtimeName]
23
+ if (version) {
24
+ targets[runtimeName] = versionToBits(version)
25
+ }
26
+ })
27
+ return targets
28
+ }
29
+
30
+ const versionToBits = (version) => {
31
+ const [major, minor = 0, patch = 0] = version
32
+ .split("-")[0]
33
+ .split(".")
34
+ .map((v) => parseInt(v, 10))
35
+ return (major << 16) | (minor << 8) | patch
36
+ }
File without changes
@@ -1,7 +1,7 @@
1
- import { minifyHtml } from "./html/minify_html.js"
2
- import { minifyCss } from "./css/minify_css.js"
3
- import { minifyJs } from "./js/minify_js.js"
4
- import { minifyJson } from "./json/minify_json.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 = {},
@@ -1,9 +0,0 @@
1
- import { minifyWithParcel } from "@jsenv/ast"
2
-
3
- export const minifyCss = ({ cssUrlInfo, context }) => {
4
- const { code, map } = minifyWithParcel(cssUrlInfo, context)
5
- return {
6
- content: String(code),
7
- sourcemap: map,
8
- }
9
- }