mirror of
https://github.com/youzan/vant.git
synced 2025-10-18 09:24:25 +00:00
refactor(@vant/cli): migrate to ESM package
This commit is contained in:
42
packages/vant-cli/cjs/postcss.config.cjs
Normal file
42
packages/vant-cli/cjs/postcss.config.cjs
Normal file
@@ -0,0 +1,42 @@
|
||||
const { join } = require('path');
|
||||
const { existsSync } = require('fs');
|
||||
const { ROOT } = require('./shared.cjs');
|
||||
|
||||
function getRootPostcssConfig() {
|
||||
const ROOT_POSTCSS_CONFIG_FILE = join(ROOT, 'postcss.config.js');
|
||||
if (existsSync(ROOT_POSTCSS_CONFIG_FILE)) {
|
||||
return require(ROOT_POSTCSS_CONFIG_FILE);
|
||||
}
|
||||
return { plugins: [] };
|
||||
}
|
||||
|
||||
function getPostcssPlugins(rootConfig) {
|
||||
const plugins = rootConfig.plugins || [];
|
||||
|
||||
if (Array.isArray(plugins)) {
|
||||
const hasPostcssPlugin = plugins.find(
|
||||
(plugin) =>
|
||||
plugin === 'autoprefixer' && plugin.postcssPlugin === 'autoprefixer'
|
||||
);
|
||||
if (hasPostcssPlugin) {
|
||||
return plugins;
|
||||
}
|
||||
|
||||
return [require('autoprefixer'), ...plugins];
|
||||
}
|
||||
|
||||
return {
|
||||
autoprefixer: {},
|
||||
...plugins,
|
||||
};
|
||||
}
|
||||
|
||||
function resolvePostcssConfig() {
|
||||
const rootConfig = getRootPostcssConfig();
|
||||
return {
|
||||
...rootConfig,
|
||||
plugins: getPostcssPlugins(rootConfig),
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = resolvePostcssConfig();
|
Reference in New Issue
Block a user