From a5ba0f89ce6d93c3ba72e709ec5d3d3c6bbd81d0 Mon Sep 17 00:00:00 2001 From: qiang Date: Fri, 9 Jun 2023 22:12:37 +0800 Subject: [PATCH] feat: support for disable automatically import styles (#20) --- README.md | 7 +++++++ src/config.ts | 1 + src/core/styles.ts | 3 ++- src/types.ts | 6 ++++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9ffa791..6bf6248 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,13 @@ How to load directives and components from lazyload. eg. `{ lazyComponent: true }` +### importStyle + +- Type: `boolean` +- Default: `true` + +Whether to automatically import styles. + ### excludeExports - Type: `array` diff --git a/src/config.ts b/src/config.ts index d896328..b343e33 100644 --- a/src/config.ts +++ b/src/config.ts @@ -49,6 +49,7 @@ const defaultExclude: RegExp[] = [ export const defaults: Options = { lazyload: false, + importStyle: true, components: allComponents, imports: allImports, excludeExports: defaultExcludeExports, diff --git a/src/core/styles.ts b/src/core/styles.ts index af0f9aa..24a4d1d 100644 --- a/src/core/styles.ts +++ b/src/core/styles.ts @@ -7,8 +7,9 @@ export function getStyleDir (name: string) { } export function resolveStyles (config: Options, name: string) { - const { components } = config + const { components, importStyle } = config + if (importStyle === false) { return undefined } if (name in allImportsWithStyle) { return getStyleDir(allImportsWithStyle[name]) } diff --git a/src/types.ts b/src/types.ts index 5ca6ea4..aa43dfd 100644 --- a/src/types.ts +++ b/src/types.ts @@ -21,6 +21,12 @@ export interface Options extends TransformOptions { * ``` */ lazyload: boolean | { lazyComponent?: boolean; lazyImage?: boolean } + /** + * Whether to automatically import style files. + * + * @default true + */ + importStyle: boolean /** * Exclude exports from Vant that are not component content. *