feat(cli): import base css

This commit is contained in:
陈嘉涵
2019-12-02 17:54:55 +08:00
parent 4299740b5d
commit 6a8a9a6f79
5 changed files with 111 additions and 30 deletions
+2
View File
@@ -10,6 +10,8 @@ export const 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');
export const STYLE_DIR = join(SRC_DIR, 'style');
export const DIST_DIR = join(__dirname, '../../dist');
export const CONFIG_DIR = join(__dirname, '../config');
+33
View File
@@ -0,0 +1,33 @@
import { get } from 'lodash';
import { join, isAbsolute } from 'path';
import { CONFIG, STYLE_DIR, SRC_DIR } from './constant';
import { existsSync } from 'fs';
type CSS_LANG = 'css' | 'less' | 'scss';
function getCssLang(): CSS_LANG {
const preprocessor = get(CONFIG, 'build.css.preprocessor', 'less');
if (preprocessor === 'sass') {
return 'scss';
}
return preprocessor;
}
export const CSS_LANG = getCssLang();
export function getCssBaseFile() {
let path = join(STYLE_DIR, `base.${CSS_LANG}`);
const baseFile = get(CONFIG, 'build.css.base', '');
if (baseFile) {
path = isAbsolute(baseFile) ? baseFile : join(SRC_DIR, baseFile);
}
if (existsSync(path)) {
return path;
}
return null;
}
+13 -2
View File
@@ -1,7 +1,8 @@
import decamelize from 'decamelize';
import { readdirSync, existsSync, lstatSync, readFileSync } from 'fs-extra';
import { join } from 'path';
import { SRC_DIR, WEBPACK_CONFIG_FILE } from './constant';
import { get } from 'lodash';
import { readdirSync, existsSync, lstatSync, readFileSync } from 'fs-extra';
import { CONFIG, SRC_DIR, WEBPACK_CONFIG_FILE } from './constant';
export const EXT_REGEXP = /\.\w+$/;
export const SFC_REGEXP = /\.(vue)$/;
@@ -103,4 +104,14 @@ 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;
}
export { decamelize };