@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.
- package/bin/config/plugins/css.js +17 -14
- package/package.json +1 -1
|
@@ -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:
|
|
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: {
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
};
|