@michijs/dev-server 0.8.5-beta.1 → 0.8.5

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.
@@ -2,17 +2,12 @@ import { build as esbuild } from "esbuild";
2
2
  import { config } from "../config.js";
3
3
  import path from "path";
4
4
  export const cssPlugin = {
5
- name: 'css import assertions',
5
+ name: "css import assertions",
6
6
  setup(build) {
7
7
  build.onLoad({ filter: /\.css$/ }, async (args) => {
8
8
  try {
9
9
  // Check if CSS is from a library (inside node_modules)
10
10
  let layerName;
11
- const parts = args.path.split(path.sep);
12
- const nodeModulesIndex = parts.lastIndexOf('node_modules');
13
- if (nodeModulesIndex !== -1 && parts[nodeModulesIndex + 1]) {
14
- layerName = parts[nodeModulesIndex + 1].replace(/[^a-zA-Z0-9_-]/g, '-'); // Sanitize name
15
- }
16
11
  const result = await esbuild({
17
12
  ...config.esbuildOptions,
18
13
  splitting: false,
@@ -23,16 +18,24 @@ export const cssPlugin = {
23
18
  entryPoints: [args.path],
24
19
  legalComments: "inline",
25
20
  // TODO: Add other image formats
26
- loader: { '.svg': 'dataurl', '.gif': 'dataurl', '.png': 'dataurl', '.webp': 'dataurl' },
21
+ loader: {
22
+ ".svg": "dataurl",
23
+ ".gif": "dataurl",
24
+ ".png": "dataurl",
25
+ ".webp": "dataurl",
26
+ },
27
27
  define: undefined,
28
28
  });
29
29
  const processedCss = result.outputFiles?.[0].text ?? "";
30
- const contents = `
31
- const styles = new CSSStyleSheet();
32
- styles.replaceSync(\`
33
- ${layerName ? `@layer ${layerName} {\n${processedCss}\n}` : processedCss}
34
- \`);
35
- export default styles;`;
30
+ if (!processedCss.includes("@layer")) {
31
+ const parts = args.path.split(path.sep);
32
+ const nodeModulesIndex = parts.lastIndexOf("node_modules");
33
+ if (nodeModulesIndex !== -1 && parts[nodeModulesIndex + 1])
34
+ layerName = parts[nodeModulesIndex + 1].replace(/[^a-zA-Z0-9_-]/g, "-"); // Sanitize name
35
+ }
36
+ const contents = `const styles = new CSSStyleSheet();
37
+ styles.replaceSync(\`${layerName ? `@layer ${layerName} {\n${processedCss}\n}` : processedCss}\`);
38
+ export default styles;`;
36
39
  return { contents };
37
40
  }
38
41
  catch (ex) {
@@ -40,5 +43,5 @@ export const cssPlugin = {
40
43
  throw ex;
41
44
  }
42
45
  });
43
- }
46
+ },
44
47
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@michijs/dev-server",
3
3
  "license": "MIT",
4
- "version": "0.8.5-beta.1",
4
+ "version": "0.8.5",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/michijs/dev-server.git"