@farmfe/js-plugin-postcss
Support postcss
for Farm.
Installationâ
- npm
- yarn
- pnpm
npm install @farmfe/js-plugin-postcss postcss
yarn add @farmfe/js-plugin-postcss postcss
pnpm add @farmfe/js-plugin-postcss postcss
Usageâ
import { UserConfig } from '@farmfe/core';
import farmJsPluginPostcss from '@farmfe/js-plugin-postcss';
const config: UserConfig = {
plugins: [
farmJsPluginPostcss({ /* options */ })
]
}
Optionsâ
export type PostcssPluginOptions = {
/**
* @default undefined
* postcss-load-config options. path default to farm.config.js root.
*/
postcssLoadConfig?: {
ctx?: postcssLoadConfig.ConfigContext;
path?: string;
options?: Parameters<typeof postcssLoadConfig>[2];
};
filters?: {
resolvedPaths?: string[];
moduleTypes?: string[];
};
implementation?: string;
};
postcssLoadConfigâ
Farm uses postcss-load-config
to load postcss
config, so you can use postcss-load-config
's options. Refer to postcss-load-config.
Example:
import path from 'node:path';
import { UserConfig } from '@farmfe/core';
import farmJsPluginPostcss from '@farmfe/js-plugin-postcss';
const config: UserConfig = {
plugins: [
farmJsPluginPostcss({
postcssLoadConfig: {
// load config from client/postcss.config.js
path: path.join(process.cwd(), 'client')
}
})
]
}
export default config;
filtersâ
Which files should be processed by postcss
. default to { moduleTypes: ['css'] }
.
resolvedPaths
: Only files under these paths will be processed. Support regex.moduleTypes
: Only files with these module types will be processed. note that less/sass files should be processed by@farmfe/js-plugin-less
/@farmfe/plugin-sass
first.
resolvedPaths
and moduleTypes
are unioned, which means files match any of them will be processed.
Example:
import { UserConfig } from '@farmfe/core';
import farmJsPluginPostcss from '@farmfe/js-plugin-postcss';
const config: UserConfig = {
plugins: [
farmJsPluginPostcss({
filters: {
// all files end with .custom-css will be processed
resolvedPaths: ['\\.custom-css$'],
moduleTypes: ['css']
}
})
]
}
export default config;
implementationâ
implementation
package name of postcss
. Default to postcss
.