Skip to content

Commit

Permalink
refactor: move PostCSSOptions to common
Browse files Browse the repository at this point in the history
  • Loading branch information
ntnyq committed Sep 17, 2024
1 parent 359e2c8 commit 6dbae17
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 25 deletions.
20 changes: 20 additions & 0 deletions src/config/common.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import type {
AutoprefixerOptions,
PostcssCssModulesOptions,
PostcssHtmlTransformOptions,
PostcssPxtransformOptions,
PostcssUrlOptions,
} from '../config/packages'
import type { LiteralUnion } from '../utility-types'

export type { LoaderContext } from 'webpack'
Expand Down Expand Up @@ -35,6 +42,8 @@ export type SourceMapType = LiteralUnion<
| 'hidden-source-map'
>

export type PlatformUnion = LiteralUnion<'h5' | 'mini' | 'rn' | 'harmony'>

export interface ConfigurablePlugin<T extends Record<string, any>> {
enable?: boolean
config?: T
Expand All @@ -56,3 +65,14 @@ export interface FilterOptions {
* 小程序编译时的文件类型集合
*/
export type ParseAstType = LiteralUnion<'ENTRY' | 'PAGE' | 'COMPONENT' | 'NORMAL' | 'STATIC'>

export interface BasePostCSSOptions {
autoprefixer?: ConfigurablePlugin<AutoprefixerOptions>
pxtransform?: ConfigurablePlugin<PostcssPxtransformOptions>
cssModules?: ConfigurablePlugin<PostcssCssModulesOptions>
htmltransform?: ConfigurablePlugin<PostcssHtmlTransformOptions>
[key: string]: any
}
export type PostCSSOptions<T extends PlatformUnion> = T extends 'h5'
? BasePostCSSOptions & { url?: ConfigurablePlugin<PostcssUrlOptions> }
: BasePostCSSOptions
1 change: 0 additions & 1 deletion src/config/packages/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ export * from './sass'
export * from './less'
export * from './stylus'
export * from './cssnano'
export * from './postcss'
export * from './css-loader'
export * from './url-loader'
export * from './sass-loader'
Expand Down
18 changes: 0 additions & 18 deletions src/config/packages/postcss.d.ts

This file was deleted.

3 changes: 1 addition & 2 deletions src/config/platforms/h5.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import type Webpack from 'webpack'
import type { LiteralUnion } from '../../utility-types'
import type { FilterOptions, ParseAstType, SourceMapType } from '../common'
import type { FilterOptions, ParseAstType, PostCSSOptions, SourceMapType } from '../common'
import type {
ChainableWebpackConfig,
CSSLoaderOptions,
HtmlWebpackPluginOptions,
LessLoaderOptions,
MiniCSSExtractPluginOptions,
PostCSSOptions,
SassLoaderOptions,
StyleLoaderOptions,
StylusLoaderOptions,
Expand Down
3 changes: 1 addition & 2 deletions src/config/platforms/harmony.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
import type { OutputOptions as RollupOutputOptions } from 'rollup'
import type Webpack from 'webpack'
import type { Configuration as WebpackConfiguration } from 'webpack'
import type { FilterOptions, SourceMapType } from '../common'
import type { FilterOptions, PostCSSOptions, SourceMapType } from '../common'
import type { CompilerTypes, CompilerViteTypes } from '../compiler'
import type {
ChainableWebpackConfig,
CSSLoaderOptions,
LessLoaderOptions,
MiniCSSExtractPluginOptions,
PostCSSOptions,
SassLoaderOptions,
StylusLoaderOptions,
URLLoaderOptions,
Expand Down
3 changes: 1 addition & 2 deletions src/config/platforms/mini.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import type Webpack from 'webpack'
import type { FilterOptions, ParseAstType, SourceMapType } from '../common'
import type { FilterOptions, ParseAstType, PostCSSOptions, SourceMapType } from '../common'
import type {
ChainableWebpackConfig,
CSSLoaderOptions,
LessLoaderOptions,
MiniCSSExtractPluginOptions,
PostCSSOptions,
SassLoaderOptions,
StyleLoaderOptions,
StylusLoaderOptions,
Expand Down

0 comments on commit 6dbae17

Please sign in to comment.