feat(cli): support custom postcss config

This commit is contained in:
陈嘉涵
2020-01-12 17:41:36 +08:00
parent 0406579b9b
commit 6ce9f5598a
4 changed files with 72 additions and 9 deletions
+18 -5
View File
@@ -7,7 +7,12 @@ import {
readFileSync,
outputFileSync
} from 'fs-extra';
import { SRC_DIR, getVantConfig, WEBPACK_CONFIG_FILE } from './constant';
import {
SRC_DIR,
getVantConfig,
ROOT_WEBPACK_CONFIG_FILE,
ROOT_POSTCSS_CONFIG_FILE
} from './constant';
export const EXT_REGEXP = /\.\w+$/;
export const SFC_REGEXP = /\.(vue)$/;
@@ -96,8 +101,8 @@ export function normalizePath(path: string): string {
}
export function getWebpackConfig(): object {
if (existsSync(WEBPACK_CONFIG_FILE)) {
const config = require(WEBPACK_CONFIG_FILE);
if (existsSync(ROOT_WEBPACK_CONFIG_FILE)) {
const config = require(ROOT_WEBPACK_CONFIG_FILE);
if (typeof config === 'function') {
return config();
@@ -109,6 +114,14 @@ export function getWebpackConfig(): object {
return {};
}
export function getPostcssConfig(): object {
if (existsSync(ROOT_POSTCSS_CONFIG_FILE)) {
return require(ROOT_POSTCSS_CONFIG_FILE);
}
return {};
}
export type ModuleEnv = 'esmodule' | 'commonjs';
export type NodeEnv = 'production' | 'development' | 'test';
export type BuildTarget = 'site' | 'package';
@@ -129,8 +142,8 @@ export function isDev() {
return process.env.NODE_ENV === 'development';
}
// Smarter outputFileSync
// Skip if content unchanged
// smarter outputFileSync
// skip output if file content unchanged
export function smartOutputFile(filePath: string, content: string) {
if (existsSync(filePath)) {
const previousContent = readFileSync(filePath, 'utf-8');