@michijs/dev-server 0.8.5-beta.2 → 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 +11 -6
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@ 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 {
|
|
@@ -18,15 +18,20 @@ export const cssPlugin = {
|
|
|
18
18
|
entryPoints: [args.path],
|
|
19
19
|
legalComments: "inline",
|
|
20
20
|
// TODO: Add other image formats
|
|
21
|
-
loader: {
|
|
21
|
+
loader: {
|
|
22
|
+
".svg": "dataurl",
|
|
23
|
+
".gif": "dataurl",
|
|
24
|
+
".png": "dataurl",
|
|
25
|
+
".webp": "dataurl",
|
|
26
|
+
},
|
|
22
27
|
define: undefined,
|
|
23
28
|
});
|
|
24
29
|
const processedCss = result.outputFiles?.[0].text ?? "";
|
|
25
|
-
if (!processedCss.includes(
|
|
30
|
+
if (!processedCss.includes("@layer")) {
|
|
26
31
|
const parts = args.path.split(path.sep);
|
|
27
|
-
const nodeModulesIndex = parts.lastIndexOf(
|
|
32
|
+
const nodeModulesIndex = parts.lastIndexOf("node_modules");
|
|
28
33
|
if (nodeModulesIndex !== -1 && parts[nodeModulesIndex + 1])
|
|
29
|
-
layerName = parts[nodeModulesIndex + 1].replace(/[^a-zA-Z0-9_-]/g,
|
|
34
|
+
layerName = parts[nodeModulesIndex + 1].replace(/[^a-zA-Z0-9_-]/g, "-"); // Sanitize name
|
|
30
35
|
}
|
|
31
36
|
const contents = `const styles = new CSSStyleSheet();
|
|
32
37
|
styles.replaceSync(\`${layerName ? `@layer ${layerName} {\n${processedCss}\n}` : processedCss}\`);
|
|
@@ -38,5 +43,5 @@ export default styles;`;
|
|
|
38
43
|
throw ex;
|
|
39
44
|
}
|
|
40
45
|
});
|
|
41
|
-
}
|
|
46
|
+
},
|
|
42
47
|
};
|