mirror of
https://github.com/WeBankFinTech/fes.js.git
synced 2025-06-29 18:09:17 +08:00
fix: 处理 postcss.config.js 不存在的情况
This commit is contained in:
parent
3538082bce
commit
c9e8ebc91b
@ -1,16 +1,25 @@
|
|||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
|
import { existsSync } from 'fs';
|
||||||
import vue from '@vitejs/plugin-vue';
|
import vue from '@vitejs/plugin-vue';
|
||||||
import vueJsx from '@vitejs/plugin-vue-jsx';
|
import vueJsx from '@vitejs/plugin-vue-jsx';
|
||||||
import { createHtmlPlugin } from 'vite-plugin-html';
|
import { createHtmlPlugin } from 'vite-plugin-html';
|
||||||
import SFCConfigBlockPlugin from './SFCConfigBlockPlugin';
|
import SFCConfigBlockPlugin from './SFCConfigBlockPlugin';
|
||||||
import getDefine from './getDefine';
|
import getDefine from './getDefine';
|
||||||
|
|
||||||
|
function getPostcssConfig(api) {
|
||||||
|
// TODO 支持其他 postcss 配置文件类型
|
||||||
|
const configPath = `${api.paths.cwd}/postcss.config.js`;
|
||||||
|
if (existsSync(configPath)) {
|
||||||
|
return require(`${api.paths.cwd}/postcss.config.js`);
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
export function getInnerCommonConfig(api) {
|
export function getInnerCommonConfig(api) {
|
||||||
const { deepmerge, resolveRuntimeEnv } = api.utils;
|
const { deepmerge, resolveRuntimeEnv } = api.utils;
|
||||||
const { server, build, define, base, ...otherViteOption } = api.config.viteOption;
|
const { server, build, define, base, ...otherViteOption } = api.config.viteOption;
|
||||||
|
|
||||||
const publicPath = base || api.config.publicPath || '/';
|
const publicPath = base || api.config.publicPath || '/';
|
||||||
const postcssConfig = require(`${api.paths.cwd}/postcss.config.js`);
|
|
||||||
|
|
||||||
return deepmerge(
|
return deepmerge(
|
||||||
{
|
{
|
||||||
@ -20,7 +29,7 @@ export function getInnerCommonConfig(api) {
|
|||||||
cacheDir: join(api.cwd, '.cache'),
|
cacheDir: join(api.cwd, '.cache'),
|
||||||
css: {
|
css: {
|
||||||
postcss: {
|
postcss: {
|
||||||
...postcssConfig,
|
...getPostcssConfig(api),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user