mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
feat(cli): postcss plugins can be array (#7560)
This commit is contained in:
parent
d78438a899
commit
1b91cd5876
@ -7,12 +7,7 @@ import {
|
||||
outputFileSync,
|
||||
} from 'fs-extra';
|
||||
import merge from 'webpack-merge';
|
||||
import {
|
||||
SRC_DIR,
|
||||
getVantConfig,
|
||||
ROOT_WEBPACK_CONFIG_FILE,
|
||||
ROOT_POSTCSS_CONFIG_FILE,
|
||||
} from './constant';
|
||||
import { SRC_DIR, getVantConfig, ROOT_WEBPACK_CONFIG_FILE } from './constant';
|
||||
import { WebpackConfig } from './types';
|
||||
|
||||
export const EXT_REGEXP = /\.\w+$/;
|
||||
@ -117,14 +112,6 @@ export function getWebpackConfig(defaultConfig: WebpackConfig): object {
|
||||
return defaultConfig;
|
||||
}
|
||||
|
||||
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';
|
||||
|
@ -1,26 +1,36 @@
|
||||
import { getPostcssConfig } from '../common';
|
||||
import { existsSync } from 'fs-extra';
|
||||
import { ROOT_POSTCSS_CONFIG_FILE } from '../common/constant';
|
||||
|
||||
type PostcssConfig = object & {
|
||||
plugins?: object;
|
||||
type PostcssConfig = {
|
||||
plugins?: Record<string, unknown> | unknown[];
|
||||
};
|
||||
|
||||
function mergePostcssConfig(config1: PostcssConfig, config2: PostcssConfig) {
|
||||
const plugins = {
|
||||
...config1.plugins,
|
||||
...config2.plugins,
|
||||
};
|
||||
export function getRootPostcssConfig(): PostcssConfig {
|
||||
if (existsSync(ROOT_POSTCSS_CONFIG_FILE)) {
|
||||
return require(ROOT_POSTCSS_CONFIG_FILE);
|
||||
}
|
||||
return { plugins: [] };
|
||||
}
|
||||
|
||||
function getPostcssPlugins(rootConfig: PostcssConfig) {
|
||||
const plugins = rootConfig.plugins || [];
|
||||
|
||||
if (Array.isArray(plugins)) {
|
||||
return [require('autoprefixer'), ...plugins];
|
||||
}
|
||||
|
||||
return {
|
||||
...config1,
|
||||
...config2,
|
||||
plugins,
|
||||
autoprefixer: {},
|
||||
...plugins,
|
||||
};
|
||||
}
|
||||
|
||||
const DEFAULT_CONFIG = {
|
||||
plugins: {
|
||||
autoprefixer: {},
|
||||
},
|
||||
};
|
||||
function resolvePostcssConfig() {
|
||||
const rootConfig = getRootPostcssConfig();
|
||||
return {
|
||||
...rootConfig,
|
||||
plugins: getPostcssPlugins(rootConfig),
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = mergePostcssConfig(DEFAULT_CONFIG, getPostcssConfig());
|
||||
module.exports = resolvePostcssConfig();
|
||||
|
Loading…
x
Reference in New Issue
Block a user