mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-24 18:36:51 +08:00
feat(cli): optimize dist file path
This commit is contained in:
parent
19a1ab37ef
commit
e2c9628316
@ -1,11 +1,10 @@
|
|||||||
import glob from 'fast-glob';
|
import glob from 'fast-glob';
|
||||||
import { join, parse, relative } from 'path';
|
import { join, parse } from 'path';
|
||||||
import { existsSync, writeFileSync } from 'fs-extra';
|
import { existsSync, writeFileSync } from 'fs-extra';
|
||||||
import { pascalize, removeExt, getComponents } from '../common';
|
import { pascalize, removeExt, getComponents } from '../common';
|
||||||
import {
|
import {
|
||||||
SRC_DIR,
|
SRC_DIR,
|
||||||
DOCS_DIR,
|
DOCS_DIR,
|
||||||
DIST_DIR,
|
|
||||||
CONFIG_FILE,
|
CONFIG_FILE,
|
||||||
DESKTOP_ENTRY_FILE
|
DESKTOP_ENTRY_FILE
|
||||||
} from '../common/constant';
|
} from '../common/constant';
|
||||||
@ -36,10 +35,7 @@ function resolveDocuments(components: string[]): DocumentItem[] {
|
|||||||
|
|
||||||
function genImportDocuments(items: DocumentItem[]) {
|
function genImportDocuments(items: DocumentItem[]) {
|
||||||
return items
|
return items
|
||||||
.map(item => {
|
.map(item => `import ${item.name} from '${item.path}';`)
|
||||||
const relativePath = relative(DIST_DIR, item.path);
|
|
||||||
return `import ${item.name} from '${relativePath}';`;
|
|
||||||
})
|
|
||||||
.join('\n');
|
.join('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,8 +46,7 @@ function genExportDocuments(items: DocumentItem[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function genImportConfig() {
|
function genImportConfig() {
|
||||||
const configRelative = relative(DIST_DIR, CONFIG_FILE);
|
return `import config from '${removeExt(CONFIG_FILE)}';`;
|
||||||
return `import config from '${removeExt(configRelative)}';`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function genExportConfig() {
|
function genExportConfig() {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { join, relative } from 'path';
|
import { join } from 'path';
|
||||||
import { existsSync, ensureDirSync, writeFileSync } from 'fs-extra';
|
import { existsSync, ensureDirSync, writeFileSync } from 'fs-extra';
|
||||||
import { decamelize, pascalize, removeExt, getComponents } from '../common';
|
import { decamelize, pascalize, removeExt, getComponents } from '../common';
|
||||||
import {
|
import {
|
||||||
@ -16,6 +16,7 @@ type DemoItem = {
|
|||||||
function genInstall() {
|
function genInstall() {
|
||||||
return `import Vue from 'vue';
|
return `import Vue from 'vue';
|
||||||
import PackageEntry from './package-entry';
|
import PackageEntry from './package-entry';
|
||||||
|
import './package-style';
|
||||||
|
|
||||||
Vue.use(PackageEntry);
|
Vue.use(PackageEntry);
|
||||||
`;
|
`;
|
||||||
@ -23,10 +24,7 @@ Vue.use(PackageEntry);
|
|||||||
|
|
||||||
function genImports(demos: DemoItem[]) {
|
function genImports(demos: DemoItem[]) {
|
||||||
return demos
|
return demos
|
||||||
.map(item => {
|
.map(item => `import ${item.name} from '${removeExt(item.path)}';`)
|
||||||
const relativePath = relative(DIST_DIR, item.path);
|
|
||||||
return `import ${item.name} from '${removeExt(relativePath)}';`;
|
|
||||||
})
|
|
||||||
.join('\n');
|
.join('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,7 +39,9 @@ function genConfig(demos: DemoItem[]) {
|
|||||||
const demoNames = demos.map(item => decamelize(item.name, '-'));
|
const demoNames = demos.map(item => decamelize(item.name, '-'));
|
||||||
|
|
||||||
CONFIG.site.nav = CONFIG.site.nav.filter((group: any) => {
|
CONFIG.site.nav = CONFIG.site.nav.filter((group: any) => {
|
||||||
group.items = group.items.filter((item: any) => (demoNames.includes(item.path)));
|
group.items = group.items.filter((item: any) =>
|
||||||
|
demoNames.includes(item.path)
|
||||||
|
);
|
||||||
return group.items.length;
|
return group.items.length;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -56,7 +56,9 @@ function genCode(components: string[]) {
|
|||||||
}))
|
}))
|
||||||
.filter(item => existsSync(item.path));
|
.filter(item => existsSync(item.path));
|
||||||
|
|
||||||
return `${genInstall()}\n${genImports(demos)}\n\n${genExports(demos)}\n${genConfig(demos)}\n`;
|
return `${genInstall()}\n${genImports(demos)}\n\n${genExports(
|
||||||
|
demos
|
||||||
|
)}\n${genConfig(demos)}\n`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function genMobileEntry() {
|
export function genMobileEntry() {
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
import { get } from 'lodash';
|
import { get } from 'lodash';
|
||||||
import { join, relative } from 'path';
|
import { join } from 'path';
|
||||||
import { writeFileSync } from 'fs-extra';
|
import { writeFileSync } from 'fs-extra';
|
||||||
import { pascalize, getComponents, replaceExt } from '../common';
|
import { pascalize, getComponents, replaceExt } from '../common';
|
||||||
import {
|
import {
|
||||||
CONFIG,
|
CONFIG,
|
||||||
SRC_DIR,
|
SRC_DIR,
|
||||||
DIST_DIR,
|
|
||||||
PACKAGE_JSON_FILE,
|
PACKAGE_JSON_FILE,
|
||||||
PACKAGE_ENTRY_FILE,
|
PACKAGE_ENTRY_FILE,
|
||||||
PACKAGE_STYLE_FILE,
|
PACKAGE_STYLE_FILE,
|
||||||
@ -20,10 +19,7 @@ const version = process.env.PACKAGE_VERSION || packageJson.version;
|
|||||||
|
|
||||||
function genImports(components: string[]): string {
|
function genImports(components: string[]): string {
|
||||||
return components
|
return components
|
||||||
.map(name => {
|
.map(name => `import ${pascalize(name)} from '${join(SRC_DIR, name)}';`)
|
||||||
const relativePath = relative(DIST_DIR, join(SRC_DIR, name));
|
|
||||||
return `import ${pascalize(name)} from '${relativePath}';`;
|
|
||||||
})
|
|
||||||
.join('\n');
|
.join('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,7 +40,7 @@ function getStyleExt(): string {
|
|||||||
function genStyleEntry() {
|
function genStyleEntry() {
|
||||||
const ext = getStyleExt();
|
const ext = getStyleExt();
|
||||||
const content = styleDepsJson.sequence
|
const content = styleDepsJson.sequence
|
||||||
.map((item: string) => `@import "./${item}/index${ext}";`)
|
.map((name: string) => `@import "${join(SRC_DIR, `${name}/index${ext}`)}";`)
|
||||||
.join('\n');
|
.join('\n');
|
||||||
|
|
||||||
writeFileSync(replaceExt(PACKAGE_STYLE_FILE, ext), content);
|
writeFileSync(replaceExt(PACKAGE_STYLE_FILE, ext), content);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user