Skip to content

Commit

Permalink
fix(vite-plugin-angular): bind css transform to correct plugin scope
Browse files Browse the repository at this point in the history
Closes #969
  • Loading branch information
brandonroberts committed Mar 28, 2024
1 parent 68a9cc8 commit 53657a9
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions packages/vite-plugin-angular/src/lib/angular-vite-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,19 @@ export function angular(options?: PluginOptions): Plugin[] {
},
configureServer(server) {
viteServer = server;
server.watcher.on('add', setupCompilation);
server.watcher.on('unlink', setupCompilation);
const context = this;
server.watcher.on('add', () => setupCompilation(userConfig, context));
server.watcher.on('unlink', () =>
setupCompilation(userConfig, context)
);
},
async buildStart({ plugins }) {
if (Array.isArray(plugins)) {
cssPlugin = plugins.find((plugin) => plugin.name === 'vite:css');
}

setupCompilation(userConfig);
const context = this;
setupCompilation(userConfig, context);

// Only store cache if in watch mode
if (watchMode) {
Expand Down Expand Up @@ -472,7 +476,7 @@ export function angular(options?: PluginOptions): Plugin[] {
.map((file: string) => `${file}.ts`);
}

function setupCompilation(config: UserConfig) {
function setupCompilation(config: UserConfig, context?: unknown) {
const analogFiles = findAnalogFiles(config);
const { options: tsCompilerOptions, rootNames: rn } =
compilerCli.readConfiguration(pluginOptions.tsconfig, {
Expand Down Expand Up @@ -506,7 +510,7 @@ export function angular(options?: PluginOptions): Plugin[] {

styleTransform = watchMode
? viteServer!.pluginContainer.transform
: (cssPlugin!.transform as PluginContainer['transform']);
: (cssPlugin!.transform as PluginContainer['transform']).bind(context);

if (!jit) {
augmentHostWithResources(host, styleTransform, {
Expand Down

0 comments on commit 53657a9

Please sign in to comment.