@aliretail/vite-config-xixi
Version:
瓴羊客服vite配置脚手架
50 lines (49 loc) • 1.76 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.getShortPkgName = exports.readPackageSync = exports.readPackage = exports.mergeConfig = exports.tapConfig = exports.streamToString = exports.cleanUrl = exports.hashRE = exports.queryRE = exports.readFile = void 0;
const fs_1 = require("fs");
const vite_1 = require("vite");
const readPkg = require("read-pkg");
exports.readFile = fs_1.promises.readFile;
exports.queryRE = /\?.*$/;
exports.hashRE = /#.*$/;
const cleanUrl = (url) => url.replace(exports.hashRE, '').replace(exports.queryRE, '');
exports.cleanUrl = cleanUrl;
function streamToString(stream) {
const chunks = [];
return new Promise((resolve, reject) => {
stream.on('data', (chunk) => chunks.push(chunk));
stream.on('error', reject);
stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')));
});
}
exports.streamToString = streamToString;
function tapConfig(config, interceptor) {
return async function modifiedConfig(env) {
const userConfig = (await (typeof config === 'function' ? config(env) : config)) || {};
return interceptor(userConfig, env) ?? userConfig;
};
}
exports.tapConfig = tapConfig;
function mergeConfig(a, b) {
return (0, vite_1.mergeConfig)(a, b);
}
exports.mergeConfig = mergeConfig;
const pkg = readPkg();
async function readPackage() {
return pkg;
}
exports.readPackage = readPackage;
function readPackageSync() {
return readPkg.sync();
}
exports.readPackageSync = readPackageSync;
function getShortPkgName(name) {
let result = '';
if (name != null) {
let ar = name.split('/');
result = ar[ar.length - 1] || '';
}
return result;
}
exports.getShortPkgName = getShortPkgName;
;