Skip to content

Commit a062b97

Browse files
committed
增加exclude
如果不需要编译,需要用户自己写行数判断
1 parent e8db0a5 commit a062b97

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/core/base-plugin.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ export class BasePlugin {
2121

2222
protected prepare({ assets }: Compilation) {
2323
Object.keys(assets).forEach((fileName) => {
24-
if (isCSS(fileName) && this.isCurrentFileNeedsToBeInlined(fileName)) {
25-
this.cssStyleCache[fileName] = assets[fileName].source()
24+
if (isCSS(fileName) && !this.isCurrentFileNeedsToBeLinked(fileName)) {
25+
if (isCSS(fileName) && this.isCurrentFileNeedsToBeInlined(fileName)) {
26+
this.cssStyleCache[fileName] = assets[fileName].source()
2627

27-
if (!this.config.leaveCSSFile) {
28-
delete assets[fileName]
28+
if (!this.config.leaveCSSFile) {
29+
delete assets[fileName]
30+
}
2931
}
3032
}
3133
})
@@ -66,6 +68,14 @@ export class BasePlugin {
6668
}
6769
}
6870

71+
protected isCurrentFileNeedsToBeLinked(fileName: string): boolean {
72+
if (typeof this.config.exclude === 'function') {
73+
return this.config.exclude(fileName)
74+
} else {
75+
return true
76+
}
77+
}
78+
6979
protected addStyle({
7080
html,
7181
htmlFileName,

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export const DEFAULT_REPLACE_CONFIG: ReplaceConfig = {
1212

1313
export interface Config {
1414
filter?(fileName: string): boolean
15+
exclude?(fileName: string): boolean
1516
leaveCSSFile?: boolean
1617
replace?: ReplaceConfig
1718
}

0 commit comments

Comments
 (0)