@michijs/dev-server 0.8.4 → 0.8.5-beta.0
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/config.js
CHANGED
|
@@ -8,6 +8,7 @@ import { fileURLToPath } from "url";
|
|
|
8
8
|
import { counterPlugin } from "./plugins/counter.js";
|
|
9
9
|
import { getCurrentCommitSha } from "../utils/getCurrentCommitSha.js";
|
|
10
10
|
import { publicFolderPlugin } from "./plugins/publicFolder.js";
|
|
11
|
+
import { cssPlugin } from "./plugins/css.js";
|
|
11
12
|
const minify = process.env.NODE_ENV === "PRODUCTION";
|
|
12
13
|
const devServerListener = process.env.NODE_ENV === "DEVELOPMENT"
|
|
13
14
|
? [getPath(`${dirname(fileURLToPath(import.meta.url))}/public/client.js`)]
|
|
@@ -88,6 +89,7 @@ const config = {
|
|
|
88
89
|
// ],
|
|
89
90
|
plugins: [
|
|
90
91
|
...(userConfig.esbuildOptions?.plugins ?? []),
|
|
92
|
+
cssPlugin,
|
|
91
93
|
publicFolderPlugin,
|
|
92
94
|
counterPlugin,
|
|
93
95
|
],
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { build as esbuild } from "esbuild";
|
|
2
|
+
import { config } from "../config.js";
|
|
3
|
+
export const cssPlugin = {
|
|
4
|
+
name: 'css import assertions',
|
|
5
|
+
setup(build) {
|
|
6
|
+
build.onLoad({ filter: /\.css$/ }, async (args) => {
|
|
7
|
+
try {
|
|
8
|
+
const result = await esbuild({
|
|
9
|
+
...config.esbuildOptions,
|
|
10
|
+
splitting: false,
|
|
11
|
+
outdir: undefined,
|
|
12
|
+
inject: undefined,
|
|
13
|
+
plugins: undefined,
|
|
14
|
+
write: false,
|
|
15
|
+
entryPoints: [args.path],
|
|
16
|
+
legalComments: "inline",
|
|
17
|
+
// TODO: Add other image formats
|
|
18
|
+
loader: { '.svg': 'dataurl', '.gif': 'dataurl', '.png': 'dataurl', '.webp': 'dataurl' },
|
|
19
|
+
define: undefined,
|
|
20
|
+
});
|
|
21
|
+
const contents = `
|
|
22
|
+
const styles = new CSSStyleSheet();
|
|
23
|
+
styles.replaceSync(\`${result.outputFiles?.[0].text ?? ""}\`);
|
|
24
|
+
export default styles;`;
|
|
25
|
+
return { contents };
|
|
26
|
+
}
|
|
27
|
+
catch (ex) {
|
|
28
|
+
console.error(ex);
|
|
29
|
+
throw ex;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
};
|