You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.3 KiB
38 lines
1.3 KiB
import { resolve } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
import VitePlugin from '@unocss/vite';
|
|
|
|
function UnoCSSAstroIntegration(options = {}, defaults) {
|
|
const {
|
|
injectEntry = true,
|
|
injectReset = false,
|
|
injectExtra = []
|
|
} = options;
|
|
return {
|
|
name: "unocss",
|
|
hooks: {
|
|
"astro:config:setup": async ({ config, injectScript }) => {
|
|
var _a, _b;
|
|
options.extraContent || (options.extraContent = {});
|
|
(_a = options.extraContent).filesystem || (_a.filesystem = []);
|
|
options.extraContent.filesystem.push(resolve(fileURLToPath(config.srcDir), "components/**/*").replace(/\\/g, "/"));
|
|
(_b = config.vite).plugins || (_b.plugins = []);
|
|
config.vite.plugins.push(...VitePlugin(options, defaults));
|
|
const injects = [];
|
|
if (injectReset) {
|
|
const resetPath = typeof injectReset === "string" ? injectReset : "@unocss/reset/tailwind.css";
|
|
injects.push(`import "${resetPath}"`);
|
|
}
|
|
if (injectEntry) {
|
|
injects.push(typeof injectEntry === "string" ? injectEntry : 'import "uno.css"');
|
|
}
|
|
if (injectExtra.length > 0)
|
|
injects.push(...injectExtra);
|
|
if (injects?.length)
|
|
injectScript("page-ssr", injects.join("\n"));
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
export { UnoCSSAstroIntegration as default };
|
|
|