@mini-umi/preset-umi
Version:
120 lines (118 loc) • 4.5 kB
JavaScript
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/commands/dev.ts
var dev_exports = {};
__export(dev_exports, {
default: () => dev_default
});
module.exports = __toCommonJS(dev_exports);
var import_utils = require("@umijs/utils");
var import_vite = require("vite");
var import_path = require("path");
var import_utils2 = require("./utils");
var import_getRoutes = require("./getRoutes");
var import_plugin_vue = __toESM(require("@vitejs/plugin-vue"));
var dev_default = (api) => {
const cwd = process.cwd();
api.registerCommand({
name: "dev",
async fn() {
const directCopyFiles = ["app.vue", "main.ts", "index.html"];
directCopyFiles.forEach((fileName) => {
api.writeTmpFile({
target: (0, import_utils.winPath)((0, import_path.join)(cwd, `./.mini-umi/${fileName}`)),
path: `./${fileName}.tpl`,
data: {}
});
});
async function resolveRoutes() {
const routesDirPath = await api.applyPlugins({
key: "modifyRoutesDir",
initialValue: api.userConfig.routesDir
});
const userRoutes = api.userConfig.routes ? api.userConfig.routes : [];
const routes = (0, import_utils.deepmerge)((0, import_getRoutes.getRoutes)({
dirPath: routesDirPath
}), userRoutes);
const routesString = (0, import_utils2.getRoutesString)(routes);
await api.writeTmpFile({
target: (0, import_utils.winPath)((0, import_path.join)(cwd, `./.mini-umi/routes.ts`)),
path: `./routes.ts.tpl`,
data: {
routes: routesString
}
});
}
await resolveRoutes();
function layout() {
try {
const layoutContent = import_utils.fsExtra.readFileSync((0, import_utils.winPath)((0, import_path.join)(cwd, "./layout/index.vue")), "utf-8");
import_utils.fsExtra.writeFileSync((0, import_utils.winPath)((0, import_path.join)(cwd, "./.mini-umi/App.vue")), layoutContent);
} catch (err) {
}
}
layout();
const userViteConfig = await api.applyPlugins({
key: "modifyViteConfig",
initialValue: api.config.viteConfig
});
const defaultViteConfig = {
plugins: [(0, import_plugin_vue.default)()]
};
const viteConfig = (0, import_utils.deepmerge)(userViteConfig, defaultViteConfig);
const server = await (0, import_vite.createServer)({
...viteConfig,
root: (0, import_path.join)(process.cwd(), "./.mini-umi"),
server: {
port: 8e3,
host: true
}
});
await server.listen();
server.printUrls();
console.log();
console.log();
console.log(
import_utils.chalk.greenBright("\u{1F389}\u{1F389}\u{1F389}\u606D\u559C\u4F60\uFF0Cmini-umi + Vue3.2 + Vite \u542F\u52A8\u6210\u529F\uFF01")
);
console.log();
console.log();
console.log();
import_utils.chokidar.watch((0, import_path.join)(cwd, "./pages"), {
ignoreInitial: true
}).on("all", async () => {
await resolveRoutes();
});
import_utils.chokidar.watch((0, import_path.join)(cwd, "./layout"), {
ignoreInitial: true
}).on("all", async () => {
layout();
await server.restart();
});
}
});
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {});
//# sourceMappingURL=dev.js.map