UNPKG

@umijs/plugins

Version:
67 lines (65 loc) 2.53 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/unocss.ts var unocss_exports = {}; __export(unocss_exports, { default: () => unocss_default }); module.exports = __toCommonJS(unocss_exports); var import_child_process = require("child_process"); var import_fs = require("fs"); var import_path = require("path"); var import_plugin_utils = require("umi/plugin-utils"); var unocss_default = (api) => { api.describe({ key: "unocss", config: { schema({ zod }) { return zod.object({ watch: zod.array(zod.any()) }); } }, enableBy: api.EnableBy.config }); const outputPath = "uno.css"; api.onBeforeCompiler(() => { if (process.env.IS_UMI_BUILD_WORKER) return; if (!(0, import_fs.existsSync)((0, import_path.join)(api.paths.cwd, "unocss.config.ts"))) api.logger.warn( "请在项目目录中添加 unocss.config.ts 文件,并配置需要的 unocss presets,否则插件将没有效果!" ); const generatedPath = (0, import_path.join)(api.paths.absTmpPath, outputPath); const binPath = (0, import_path.join)(api.cwd, "node_modules/.bin/unocss"); const watchDirs = api.config.unocss.watch; const unocss = (0, import_child_process.exec)( `${binPath} ${watchDirs.join(" ")} --out-file ${generatedPath} ${api.env === "development" ? "--watch" : ""}`, { cwd: api.cwd } ); unocss.on("error", (m) => { api.logger.error("unocss service encounter an error: " + m); }); }); api.addEntryImports(() => { const generatedPath = (0, import_plugin_utils.winPath)((0, import_path.join)(api.paths.absTmpPath, outputPath)); return [{ source: generatedPath }]; }); }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = {});