@vant/cli
Version:
Vant CLI is a tool for building vue component library. You can quickly build a full-featured Vue component library with vant-cli.
39 lines (38 loc) • 1.28 kB
JavaScript
import { join } from 'node:path';
import { existsSync } from 'node:fs';
import { createRequire } from 'node:module';
import { smartOutputFile, normalizePath } from '../common/index.js';
import { CSS_LANG, getCssBaseFile } from '../common/css.js';
import { SRC_DIR, STYLE_DEPS_JSON_FILE } from '../common/constant.js';
export function genPackageStyle(options = {}) {
const require = createRequire(import.meta.url);
const styleDepsJson = require(STYLE_DEPS_JSON_FILE);
const ext = '.' + CSS_LANG;
let content = '';
let baseFile = getCssBaseFile();
if (baseFile) {
if (options.pathResolver) {
baseFile = options.pathResolver(baseFile);
}
content += `@import "${normalizePath(baseFile)}";\n`;
}
content += styleDepsJson.sequence
.map((name) => {
let path = join(SRC_DIR, `${name}/index${ext}`);
if (!existsSync(path)) {
return '';
}
if (options.pathResolver) {
path = options.pathResolver(path);
}
return `@import "${normalizePath(path)}";`;
})
.filter((item) => !!item)
.join('\n');
if (options.outputPath) {
smartOutputFile(options.outputPath, content);
}
else {
return content;
}
}