mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-10-03 15:29:58 +08:00
feat(cli): reload vant config
This commit is contained in:
parent
b19b287276
commit
207089b2ca
@ -6,7 +6,7 @@ export const LIB_DIR = join(CWD, 'lib');
|
|||||||
export const SRC_DIR = join(CWD, 'src');
|
export const SRC_DIR = join(CWD, 'src');
|
||||||
export const DOCS_DIR = join(CWD, 'docs');
|
export const DOCS_DIR = join(CWD, 'docs');
|
||||||
export const SITE_DIST_DIR = join(CWD, 'site');
|
export const SITE_DIST_DIR = join(CWD, 'site');
|
||||||
export const CONFIG_FILE = join(CWD, 'vant.config.js');
|
export const VANT_CONFIG_FILE = join(CWD, 'vant.config.js');
|
||||||
export const PACKAGE_JSON_FILE = join(CWD, 'package.json');
|
export const PACKAGE_JSON_FILE = join(CWD, 'package.json');
|
||||||
export const WEBPACK_CONFIG_FILE = join(CWD, 'webpack.config.js');
|
export const WEBPACK_CONFIG_FILE = join(CWD, 'webpack.config.js');
|
||||||
|
|
||||||
@ -31,5 +31,4 @@ export const JEST_STYLE_MOCK_FILE = join(CONFIG_DIR, 'jest.style-mock.js');
|
|||||||
export const SCRIPT_EXTS = ['.js', '.jsx', '.vue', '.ts', '.tsx'];
|
export const SCRIPT_EXTS = ['.js', '.jsx', '.vue', '.ts', '.tsx'];
|
||||||
export const STYLE_EXTS = ['.css', '.less', '.scss'];
|
export const STYLE_EXTS = ['.css', '.less', '.scss'];
|
||||||
|
|
||||||
export const CONFIG = require(CONFIG_FILE);
|
|
||||||
export const PACKAGE_JSON = require(PACKAGE_JSON_FILE);
|
export const PACKAGE_JSON = require(PACKAGE_JSON_FILE);
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
import { get } from 'lodash';
|
import { get } from 'lodash';
|
||||||
import { join, isAbsolute } from 'path';
|
|
||||||
import { CONFIG, STYLE_DIR, SRC_DIR } from './constant';
|
|
||||||
import { existsSync } from 'fs';
|
import { existsSync } from 'fs';
|
||||||
|
import { join, isAbsolute } from 'path';
|
||||||
|
import { getVantConfig } from '../common';
|
||||||
|
import { STYLE_DIR, SRC_DIR } from './constant';
|
||||||
|
|
||||||
type CSS_LANG = 'css' | 'less' | 'scss';
|
type CSS_LANG = 'css' | 'less' | 'scss';
|
||||||
|
|
||||||
function getCssLang(): CSS_LANG {
|
function getCssLang(): CSS_LANG {
|
||||||
const preprocessor = get(CONFIG, 'build.css.preprocessor', 'less');
|
const vantConfig = getVantConfig();
|
||||||
|
const preprocessor = get(vantConfig, 'build.css.preprocessor', 'less');
|
||||||
|
|
||||||
if (preprocessor === 'sass') {
|
if (preprocessor === 'sass') {
|
||||||
return 'scss';
|
return 'scss';
|
||||||
@ -18,9 +20,10 @@ function getCssLang(): CSS_LANG {
|
|||||||
export const CSS_LANG = getCssLang();
|
export const CSS_LANG = getCssLang();
|
||||||
|
|
||||||
export function getCssBaseFile() {
|
export function getCssBaseFile() {
|
||||||
|
const vantConfig = getVantConfig();
|
||||||
let path = join(STYLE_DIR, `base.${CSS_LANG}`);
|
let path = join(STYLE_DIR, `base.${CSS_LANG}`);
|
||||||
|
|
||||||
const baseFile = get(CONFIG, 'build.css.base', '');
|
const baseFile = get(vantConfig, 'build.css.base', '');
|
||||||
if (baseFile) {
|
if (baseFile) {
|
||||||
path = isAbsolute(baseFile) ? baseFile : join(SRC_DIR, baseFile);
|
path = isAbsolute(baseFile) ? baseFile : join(SRC_DIR, baseFile);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import decamelize from 'decamelize';
|
import decamelize from 'decamelize';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import { get } from 'lodash';
|
|
||||||
import {
|
import {
|
||||||
lstatSync,
|
lstatSync,
|
||||||
existsSync,
|
existsSync,
|
||||||
@ -8,7 +7,7 @@ import {
|
|||||||
readFileSync,
|
readFileSync,
|
||||||
outputFileSync
|
outputFileSync
|
||||||
} from 'fs-extra';
|
} from 'fs-extra';
|
||||||
import { CONFIG, SRC_DIR, WEBPACK_CONFIG_FILE } from './constant';
|
import { SRC_DIR, WEBPACK_CONFIG_FILE, VANT_CONFIG_FILE } from './constant';
|
||||||
|
|
||||||
export const EXT_REGEXP = /\.\w+$/;
|
export const EXT_REGEXP = /\.\w+$/;
|
||||||
export const SFC_REGEXP = /\.(vue)$/;
|
export const SFC_REGEXP = /\.(vue)$/;
|
||||||
@ -81,6 +80,12 @@ export function pascalize(str: string): string {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getVantConfig() {
|
||||||
|
delete require.cache[VANT_CONFIG_FILE];
|
||||||
|
|
||||||
|
return require(VANT_CONFIG_FILE);
|
||||||
|
}
|
||||||
|
|
||||||
export function getWebpackConfig(): object {
|
export function getWebpackConfig(): object {
|
||||||
if (existsSync(WEBPACK_CONFIG_FILE)) {
|
if (existsSync(WEBPACK_CONFIG_FILE)) {
|
||||||
const config = require(WEBPACK_CONFIG_FILE);
|
const config = require(WEBPACK_CONFIG_FILE);
|
||||||
@ -110,16 +115,6 @@ export function isDev() {
|
|||||||
return process.env.NODE_ENV === 'development';
|
return process.env.NODE_ENV === 'development';
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getCssLang(): string {
|
|
||||||
const preprocessor = get(CONFIG, 'build.css.preprocessor', 'less');
|
|
||||||
|
|
||||||
if (preprocessor === 'sass') {
|
|
||||||
return 'scss';
|
|
||||||
}
|
|
||||||
|
|
||||||
return preprocessor;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Smarter outputFileSync
|
// Smarter outputFileSync
|
||||||
// Skip if content unchanged
|
// Skip if content unchanged
|
||||||
export function smartOutputFile(filePath: string, content: string) {
|
export function smartOutputFile(filePath: string, content: string) {
|
||||||
|
@ -10,7 +10,7 @@ import {
|
|||||||
import {
|
import {
|
||||||
SRC_DIR,
|
SRC_DIR,
|
||||||
DOCS_DIR,
|
DOCS_DIR,
|
||||||
CONFIG_FILE,
|
VANT_CONFIG_FILE,
|
||||||
SITE_DESKTOP_SHARED_FILE
|
SITE_DESKTOP_SHARED_FILE
|
||||||
} from '../common/constant';
|
} from '../common/constant';
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ function genExportDocuments(items: DocumentItem[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function genImportConfig() {
|
function genImportConfig() {
|
||||||
return `import config from '${removeExt(CONFIG_FILE)}';`;
|
return `import config from '${removeExt(VANT_CONFIG_FILE)}';`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function genExportConfig() {
|
function genExportConfig() {
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import { existsSync } from 'fs-extra';
|
import { existsSync } from 'fs-extra';
|
||||||
import { decamelize, pascalize, removeExt, getComponents, smartOutputFile } from '../common';
|
import { SRC_DIR, SITE_MODILE_SHARED_FILE } from '../common/constant';
|
||||||
import {
|
import {
|
||||||
CONFIG,
|
pascalize,
|
||||||
SRC_DIR,
|
removeExt,
|
||||||
SITE_MODILE_SHARED_FILE
|
decamelize,
|
||||||
} from '../common/constant';
|
getVantConfig,
|
||||||
|
getComponents,
|
||||||
|
smartOutputFile
|
||||||
|
} from '../common';
|
||||||
|
|
||||||
type DemoItem = {
|
type DemoItem = {
|
||||||
name: string;
|
name: string;
|
||||||
@ -34,16 +37,17 @@ function genExports(demos: DemoItem[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function genConfig(demos: DemoItem[]) {
|
function genConfig(demos: DemoItem[]) {
|
||||||
|
const vantConfig = getVantConfig();
|
||||||
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) => {
|
vantConfig.site.nav = vantConfig.site.nav.filter((group: any) => {
|
||||||
group.items = group.items.filter((item: any) =>
|
group.items = group.items.filter((item: any) =>
|
||||||
demoNames.includes(item.path)
|
demoNames.includes(item.path)
|
||||||
);
|
);
|
||||||
return group.items.length;
|
return group.items.length;
|
||||||
});
|
});
|
||||||
|
|
||||||
return `export const config = ${JSON.stringify(CONFIG, null, 2)}`;
|
return `export const config = ${JSON.stringify(vantConfig, null, 2)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function genCode(components: string[]) {
|
function genCode(components: string[]) {
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import merge from 'webpack-merge';
|
import merge from 'webpack-merge';
|
||||||
import { baseConfig } from './webpack.base';
|
import { baseConfig } from './webpack.base';
|
||||||
import { getWebpackConfig } from '../common';
|
import { getVantConfig, getWebpackConfig } from '../common';
|
||||||
import { LIB_DIR, CONFIG, PACKAGE_ENTRY_FILE } from '../common/constant';
|
import { LIB_DIR, PACKAGE_ENTRY_FILE } from '../common/constant';
|
||||||
|
|
||||||
const { name } = CONFIG;
|
|
||||||
|
|
||||||
export function packageConfig(isMinify: boolean) {
|
export function packageConfig(isMinify: boolean) {
|
||||||
|
const { name } = getVantConfig();
|
||||||
|
|
||||||
return merge(
|
return merge(
|
||||||
baseConfig as any,
|
baseConfig as any,
|
||||||
{
|
{
|
||||||
|
@ -2,15 +2,14 @@ import merge from 'webpack-merge';
|
|||||||
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import { baseConfig } from './webpack.base';
|
import { baseConfig } from './webpack.base';
|
||||||
import { getWebpackConfig } from '../common';
|
import { getVantConfig, getWebpackConfig } from '../common';
|
||||||
import { VantCliSitePlugin } from '../compiler/vant-cli-site-plugin';
|
import { VantCliSitePlugin } from '../compiler/vant-cli-site-plugin';
|
||||||
import {
|
import {
|
||||||
CONFIG,
|
|
||||||
SITE_MODILE_SHARED_FILE,
|
SITE_MODILE_SHARED_FILE,
|
||||||
SITE_DESKTOP_SHARED_FILE
|
SITE_DESKTOP_SHARED_FILE
|
||||||
} from '../common/constant';
|
} from '../common/constant';
|
||||||
|
|
||||||
const siteConfig = CONFIG.site;
|
const siteConfig = getVantConfig().site;
|
||||||
const title = `${siteConfig.title} - ${siteConfig.description}`;
|
const title = `${siteConfig.title} - ${siteConfig.description}`;
|
||||||
|
|
||||||
export const siteDevBaseConfig = merge(baseConfig as any, {
|
export const siteDevBaseConfig = merge(baseConfig as any, {
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
import merge from 'webpack-merge';
|
import merge from 'webpack-merge';
|
||||||
import { get } from 'lodash';
|
import { get } from 'lodash';
|
||||||
import { getWebpackConfig } from '../common';
|
import { getVantConfig, getWebpackConfig } from '../common';
|
||||||
import { siteDevBaseConfig } from './webpack.site.dev';
|
import { siteDevBaseConfig } from './webpack.site.dev';
|
||||||
import { CONFIG, SITE_DIST_DIR } from '../common/constant';
|
import { SITE_DIST_DIR } from '../common/constant';
|
||||||
|
|
||||||
const outputDir = get(CONFIG, 'build.site.outputDir', SITE_DIST_DIR);
|
const vantConfig = getVantConfig();
|
||||||
|
const outputDir = get(vantConfig, 'build.site.outputDir', SITE_DIST_DIR);
|
||||||
const publicPath = get(CONFIG, 'build.site.publicPath', '/');
|
const publicPath = get(vantConfig, 'build.site.publicPath', '/');
|
||||||
|
|
||||||
export const sitePrdConfig = merge(
|
export const sitePrdConfig = merge(
|
||||||
siteDevBaseConfig,
|
siteDevBaseConfig,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user