diff --git a/src/compiler/build/compiler-ctx.ts b/src/compiler/build/compiler-ctx.ts index d193cd73b02..92922caa715 100644 --- a/src/compiler/build/compiler-ctx.ts +++ b/src/compiler/build/compiler-ctx.ts @@ -20,7 +20,7 @@ export class CompilerContext implements d.CompilerCtx { addWatchDir: (path: string) => void = noop; addWatchFile: (path: string) => void = noop; cache: d.Cache; - cachedStyleMeta = new Map(); + cssModuleImports = new Map(); changedFiles = new Set(); changedModules = new Set(); collections: d.CollectionCompilerMeta[] = []; @@ -43,7 +43,7 @@ export class CompilerContext implements d.CompilerCtx { reset() { this.cache.clear(); - this.cachedStyleMeta.clear(); + this.cssModuleImports.clear(); this.cachedGlobalStyle = null; this.collections.length = 0; this.compilerOptions = null; diff --git a/src/compiler/style/global-styles.ts b/src/compiler/style/global-styles.ts index b592b844ef3..d2869417934 100644 --- a/src/compiler/style/global-styles.ts +++ b/src/compiler/style/global-styles.ts @@ -43,8 +43,16 @@ const buildGlobalStyles = async (config: d.Config, compilerCtx: d.CompilerCtx, b globalStylePath, ); compilerCtx.cachedGlobalStyle = optimizedCss; + if (Array.isArray(transformResults.dependencies)) { - transformResults.dependencies.forEach(dep => compilerCtx.addWatchFile(dep)); + const cssModuleImports = compilerCtx.cssModuleImports.get(globalStylePath) || []; + transformResults.dependencies.forEach(dep => { + compilerCtx.addWatchFile(dep); + if (!cssModuleImports.includes(dep)) { + cssModuleImports.push(dep); + } + }); + compilerCtx.cssModuleImports.set(globalStylePath, cssModuleImports); } return optimizedCss; } @@ -75,6 +83,11 @@ const canSkipGlobalStyles = async (config: d.Config, compilerCtx: d.CompilerCtx, return false; } + const cssModuleImports = compilerCtx.cssModuleImports.get(config.globalStyle); + if (cssModuleImports && buildCtx.filesChanged.some(f => cssModuleImports.includes(f))) { + return false; + } + const hasChangedImports = await hasChangedImportFile( config, compilerCtx, diff --git a/src/declarations/stencil-private.ts b/src/declarations/stencil-private.ts index f7e613d7852..d1e6cc427dc 100644 --- a/src/declarations/stencil-private.ts +++ b/src/declarations/stencil-private.ts @@ -617,7 +617,7 @@ export interface CompilerCtx { addWatchDir: (path: string, recursive: boolean) => void; addWatchFile: (path: string) => void; cache: Cache; - cachedStyleMeta: Map; + cssModuleImports: Map; cachedGlobalStyle: string; collections: CollectionCompilerMeta[]; compilerOptions: any; diff --git a/src/testing/mocks.ts b/src/testing/mocks.ts index 8c8bb5aff3e..ad16aa33f60 100644 --- a/src/testing/mocks.ts +++ b/src/testing/mocks.ts @@ -68,7 +68,7 @@ export function mockCompilerCtx(config?: Config) { collections: [], compilerOptions: null, cache: null, - cachedStyleMeta: new Map(), + cssModuleImports: new Map(), events: null, fs: null, hasSuccessfulBuild: false,