@michijs/dev-server 0.8.5-beta.0 → 0.8.5-beta.2

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