@@ -163,38 +163,67 @@ const matchComponents: IMatcher[] = [
163
163
164
164
export interface AntDesignVueResolverOptions {
165
165
/**
166
- * import less along with components
166
+ * import style along with components
167
+ *
168
+ * @default true
169
+ */
170
+ importStyle ?: boolean
171
+ /**
172
+ * import css along with components
167
173
*
168
174
* @default true
169
175
*/
176
+ importCss ?: boolean
177
+ /**
178
+ * import less along with components
179
+ *
180
+ * @default false
181
+ */
170
182
importLess ?: boolean
171
183
}
172
184
185
+ const getStyleDir = ( compName : string ) : string => {
186
+ let styleDir
187
+ const total = matchComponents . length
188
+ for ( let i = 0 ; i < total ; i ++ ) {
189
+ const matcher = matchComponents [ i ]
190
+ if ( compName . match ( matcher . pattern ) ) {
191
+ styleDir = matcher . styleDir
192
+ break
193
+ }
194
+ }
195
+ if ( ! styleDir ) styleDir = kebabCase ( compName )
196
+
197
+ return styleDir
198
+ }
199
+
200
+ const getSideEffects : (
201
+ compName : string ,
202
+ opts : AntDesignVueResolverOptions
203
+ ) => string | undefined = ( compName , opts ) => {
204
+ const { importStyle = true , importCss = true , importLess = false } = opts
205
+
206
+ if ( importStyle ) {
207
+ if ( importLess ) {
208
+ const styleDir = getStyleDir ( compName )
209
+ return `ant-design-vue/es/${ styleDir } /style`
210
+ }
211
+ else if ( importCss ) {
212
+ const styleDir = getStyleDir ( compName )
213
+ return `ant-design-vue/es/${ styleDir } /style/css`
214
+ }
215
+ }
216
+ }
217
+
173
218
export const AntDesignVueResolver
174
219
= ( options : AntDesignVueResolverOptions = { } ) : ComponentResolver =>
175
220
( name : string ) => {
176
221
if ( name . match ( / ^ A [ A - Z ] / ) ) {
177
- const { importLess = true } = options
178
222
const importName = name . slice ( 1 )
179
- let styleDir
180
- if ( importLess ) {
181
- const total = matchComponents . length
182
- for ( let i = 0 ; i < total ; i ++ ) {
183
- const matcher = matchComponents [ i ]
184
- if ( importName . match ( matcher . pattern ) ) {
185
- styleDir = matcher . styleDir
186
- break
187
- }
188
- }
189
- if ( ! styleDir ) styleDir = kebabCase ( importName )
190
- }
191
-
192
223
return {
193
224
importName,
194
225
path : 'ant-design-vue/es' ,
195
- sideEffects : importLess
196
- ? `ant-design-vue/es/${ styleDir } /style`
197
- : undefined ,
226
+ sideEffects : getSideEffects ( importName , options ) ,
198
227
}
199
228
}
200
229
}
0 commit comments