@vitjs/vit
Version:
🛠React application framework inspired by UmiJS.
26 lines (25 loc) • 1.1 kB
JavaScript
;
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 upperFirst_1 = __importDefault(require("lodash/upperFirst"));
const mustache_1 = __importDefault(require("mustache"));
function generateHistory(options) {
const { service, history, base } = options;
const { type = 'browser', options: historyOptions = {} } = history || {};
const historyTpl = (0, fs_1.readFileSync)((0, path_1.resolve)(__dirname, './history.tpl'), 'utf-8');
service.writeTmpFile({
path: 'history.ts',
content: mustache_1.default.render(historyTpl, {
creator: `create${(0, upperFirst_1.default)(type)}History`,
options: JSON.stringify({
...historyOptions,
...(type === 'browser' || type === 'hash' ? { basename: base || '/' } : {}),
}, null, 2),
}),
});
}
exports.default = generateHistory;