feat(cli): reload vant config
This commit is contained in:
@@ -6,7 +6,7 @@ export const LIB_DIR = join(CWD, 'lib');
|
||||
export const SRC_DIR = join(CWD, 'src');
|
||||
export const DOCS_DIR = join(CWD, 'docs');
|
||||
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 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 STYLE_EXTS = ['.css', '.less', '.scss'];
|
||||
|
||||
export const CONFIG = require(CONFIG_FILE);
|
||||
export const PACKAGE_JSON = require(PACKAGE_JSON_FILE);
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
import { get } from 'lodash';
|
||||
import { join, isAbsolute } from 'path';
|
||||
import { CONFIG, STYLE_DIR, SRC_DIR } from './constant';
|
||||
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';
|
||||
|
||||
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') {
|
||||
return 'scss';
|
||||
@@ -18,9 +20,10 @@ function getCssLang(): CSS_LANG {
|
||||
export const CSS_LANG = getCssLang();
|
||||
|
||||
export function getCssBaseFile() {
|
||||
const vantConfig = getVantConfig();
|
||||
let path = join(STYLE_DIR, `base.${CSS_LANG}`);
|
||||
|
||||
const baseFile = get(CONFIG, 'build.css.base', '');
|
||||
const baseFile = get(vantConfig, 'build.css.base', '');
|
||||
if (baseFile) {
|
||||
path = isAbsolute(baseFile) ? baseFile : join(SRC_DIR, baseFile);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import decamelize from 'decamelize';
|
||||
import { join } from 'path';
|
||||
import { get } from 'lodash';
|
||||
import {
|
||||
lstatSync,
|
||||
existsSync,
|
||||
@@ -8,7 +7,7 @@ import {
|
||||
readFileSync,
|
||||
outputFileSync
|
||||
} 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 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 {
|
||||
if (existsSync(WEBPACK_CONFIG_FILE)) {
|
||||
const config = require(WEBPACK_CONFIG_FILE);
|
||||
@@ -110,16 +115,6 @@ export function isDev() {
|
||||
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
|
||||
// Skip if content unchanged
|
||||
export function smartOutputFile(filePath: string, content: string) {
|
||||
|
||||
Reference in New Issue
Block a user