From a062b97e865309a3fb798c5120697ac321b82752 Mon Sep 17 00:00:00 2001 From: KAI Date: Fri, 25 Oct 2019 16:19:16 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0exclude?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 如果不需要编译,需要用户自己写行数判断 --- src/core/base-plugin.ts | 18 ++++++++++++++---- src/types.ts | 1 + 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/core/base-plugin.ts b/src/core/base-plugin.ts index 6deda5d..783e645 100644 --- a/src/core/base-plugin.ts +++ b/src/core/base-plugin.ts @@ -21,11 +21,13 @@ export class BasePlugin { protected prepare({ assets }: Compilation) { Object.keys(assets).forEach((fileName) => { - if (isCSS(fileName) && this.isCurrentFileNeedsToBeInlined(fileName)) { - this.cssStyleCache[fileName] = assets[fileName].source() + if (isCSS(fileName) && !this.isCurrentFileNeedsToBeLinked(fileName)) { + if (isCSS(fileName) && this.isCurrentFileNeedsToBeInlined(fileName)) { + this.cssStyleCache[fileName] = assets[fileName].source() - if (!this.config.leaveCSSFile) { - delete assets[fileName] + if (!this.config.leaveCSSFile) { + delete assets[fileName] + } } } }) @@ -66,6 +68,14 @@ export class BasePlugin { } } + protected isCurrentFileNeedsToBeLinked(fileName: string): boolean { + if (typeof this.config.exclude === 'function') { + return this.config.exclude(fileName) + } else { + return true + } + } + protected addStyle({ html, htmlFileName, diff --git a/src/types.ts b/src/types.ts index 4b9660e..354a60a 100644 --- a/src/types.ts +++ b/src/types.ts @@ -12,6 +12,7 @@ export const DEFAULT_REPLACE_CONFIG: ReplaceConfig = { export interface Config { filter?(fileName: string): boolean + exclude?(fileName: string): boolean leaveCSSFile?: boolean replace?: ReplaceConfig } From 8b5726bcc674b98e88b7a34da5d29da29f720955 Mon Sep 17 00:00:00 2001 From: KAI Date: Tue, 19 Nov 2019 21:45:10 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=94=B9=E5=90=8D=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit whatever the name is --- src/core/base-plugin.ts | 4 ++-- src/types.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/base-plugin.ts b/src/core/base-plugin.ts index 783e645..3265f31 100644 --- a/src/core/base-plugin.ts +++ b/src/core/base-plugin.ts @@ -69,8 +69,8 @@ export class BasePlugin { } protected isCurrentFileNeedsToBeLinked(fileName: string): boolean { - if (typeof this.config.exclude === 'function') { - return this.config.exclude(fileName) + if (typeof this.config.ignore === 'function') { + return this.config.ignore(fileName) } else { return true } diff --git a/src/types.ts b/src/types.ts index 354a60a..fea1d71 100644 --- a/src/types.ts +++ b/src/types.ts @@ -12,7 +12,7 @@ export const DEFAULT_REPLACE_CONFIG: ReplaceConfig = { export interface Config { filter?(fileName: string): boolean - exclude?(fileName: string): boolean + ignore?(fileName: string): boolean leaveCSSFile?: boolean replace?: ReplaceConfig }