UNPKG

@vitjs/vit

Version:

🛠 React application framework inspired by UmiJS.

27 lines (26 loc) • 1.22 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const fs_1 = require("fs"); const path_1 = require("path"); const get_1 = __importDefault(require("lodash/get")); function exportStatic(options) { const { config, service } = options; const isExportStatic = (0, get_1.default)(config, 'exportStatic'); const isHistoryRouter = (0, get_1.default)(config, 'history.type', 'history') === 'history'; if (!isExportStatic || !isHistoryRouter) { return; } const entry = (0, fs_1.readFileSync)((0, path_1.join)(service.paths.absOutputPath, './index.html'), 'utf-8'); const routes = service.route.getPaths({ routes: service.route.routes }).filter((item) => item !== '/'); routes.map((item) => { const routeEntryPath = (0, path_1.join)(service.paths.absOutputPath, item, './index.html'); if (service.debug) { console.log('[@vitjs/vit] extra route entry:', routeEntryPath); } service.writeFile({ path: routeEntryPath, content: entry }); }); } exports.default = exportStatic;