Skip to content

Commit

Permalink
Remove unused webpack-plugin compiler cache (#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattcompiles committed Jul 30, 2021
1 parent b31b0eb commit c3d9d78
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 27 deletions.
5 changes: 5 additions & 0 deletions .changeset/strong-coats-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@vanilla-extract/webpack-plugin': patch
---

Remove unused compiler cache
24 changes: 1 addition & 23 deletions packages/webpack-plugin/src/compiler.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import type { LoaderContext } from './types';
import createCompat from './compat';
import { debug } from './logger';

const log = debug('vanilla-extract:compiler');

// Should be "ExternalsItem" but webpack doesn't expose it
type Externals = any;
Expand All @@ -18,39 +15,20 @@ const getCompilerName = (resource: string) =>

export class ChildCompiler {
externals: Externals | undefined;
cache: Map<string, Promise<CompilationResult>>;

constructor(externals: Externals) {
this.cache = new Map();
this.externals = externals;
}

clearCache() {
log('Clearing child compiler cache');
this.cache.clear();
}

isChildCompiler(name: string | undefined) {
return (
typeof name === 'string' && name.startsWith('vanilla-extract-compiler')
);
}

async getCompiledSource(loader: LoaderContext) {
const cacheId = loader.resourcePath;
let compilationPromise = this.cache.get(cacheId);

if (!compilationPromise) {
log('No cached compilation. Compiling: %s', cacheId);
compilationPromise = compileVanillaSource(loader, this.externals);

this.cache.set(cacheId, compilationPromise);
} else {
log('Using cached compilation: %s', cacheId);
}

const { source, fileDependencies, contextDependencies } =
await compilationPromise;
await compileVanillaSource(loader, this.externals);

// Set loader dependencies to dependencies of the child compiler
fileDependencies.forEach((dep) => {
Expand Down
4 changes: 0 additions & 4 deletions packages/webpack-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,6 @@ export class VanillaExtractPlugin {
Boolean(compiler.webpack && compiler.webpack.version),
);

compiler.hooks.watchRun.tap(pluginName, () => {
this.childCompiler.clearCache();
});

if (!compiler.parentCompilation && !this.allowRuntime) {
compiler.hooks.compilation.tap(pluginName, (compilation) => {
compilation.hooks.afterOptimizeModules.tap(pluginName, (modules) => {
Expand Down

0 comments on commit c3d9d78

Please sign in to comment.