@elenajs/plugin-rollup-css 1.0.0-beta.2 → 1.0.0-rc.3

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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/index.js +9 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elenajs/plugin-rollup-css",
3
- "version": "1.0.0-beta.2",
3
+ "version": "1.0.0-rc.3",
4
4
  "description": "Rollup plugin that minifies individual CSS files and optionally concatenates them into a single bundle.",
5
5
  "author": "Elena <hi@elenajs.com>",
6
6
  "homepage": "https://elenajs.com/",
@@ -38,5 +38,5 @@
38
38
  "devDependencies": {
39
39
  "vitest": "4.1.0"
40
40
  },
41
- "gitHead": "18e13f305c8823f7633c739f2ec61cec2420267b"
41
+ "gitHead": "aca5a63b91b07f425af4ad84003900bd74c945c4"
42
42
  }
package/src/index.js CHANGED
@@ -29,6 +29,7 @@ export function minifyCss(css, filename = "style.css") {
29
29
  code: Buffer.from(css),
30
30
  minify: true,
31
31
  });
32
+
32
33
  return code.toString();
33
34
  }
34
35
 
@@ -49,14 +50,17 @@ export function cssModuleScriptPlugin() {
49
50
  if (!source.endsWith(".css") || options?.attributes?.type !== "css") {
50
51
  return null;
51
52
  }
53
+
52
54
  return { id: PREFIX + resolve(dirname(importer), source) };
53
55
  },
54
56
  load(id) {
55
57
  if (!id.startsWith(PREFIX)) {
56
58
  return null;
57
59
  }
60
+
58
61
  const filePath = id.slice(PREFIX.length);
59
62
  const css = minifyCss(readFileSync(filePath, "utf8"), basename(filePath));
63
+
60
64
  return `const sheet = new CSSStyleSheet();\nsheet.replaceSync(${JSON.stringify(css)});\nexport default sheet;`;
61
65
  },
62
66
  };
@@ -74,12 +78,15 @@ export function cssStaticStylesPlugin() {
74
78
  if (!id.endsWith(".js") && !id.endsWith(".ts")) {
75
79
  return null;
76
80
  }
81
+
77
82
  if (!code.includes("static styles")) {
78
83
  return null;
79
84
  }
85
+
80
86
  const newCode = code.replace(/static\s+styles\s*=\s*`([\s\S]*?)`/g, (_match, css) => {
81
87
  return `static styles = \`${minifyCss(css)}\``;
82
88
  });
89
+
83
90
  return newCode !== code ? { code: newCode } : null;
84
91
  },
85
92
  };
@@ -104,7 +111,9 @@ export function cssPlugin(srcDir) {
104
111
  if (this.addWatchFile) {
105
112
  this.addWatchFile(resolve(file));
106
113
  }
114
+
107
115
  const source = minifyCss(readFileSync(file, "utf8"), basename(file));
116
+
108
117
  this.emitFile({ type: "asset", fileName: basename(file), source });
109
118
  }
110
119
  },