Skip to content

Commit

Permalink
(feat): Production file replacements
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverMira committed Jan 3, 2021
1 parent c04d38d commit e92dc20
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/compilerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export class AngularCompilerService {
private _typeCheckErrorListenerId = 0;
private _typeCheckWorker?: TypeCheckWorker;
private _lastTypeCheckResult: ng.Diagnostics = [];
private _fileReplacements = new Map<string, string>();

constructor(
angularJson: string,
Expand Down Expand Up @@ -94,6 +95,26 @@ export class AngularCompilerService {
const contents = await fsp.readFile(fileName, 'utf-8');
return contents;
};
const oriReadFile = host.readFile;
if (process.env.NODE_ENV === 'production') {
const replacementConfig = this.angularConfig.getProject(
this.angularProject
).architect.build.configurations.production.fileReplacements;
replacementConfig.forEach((replacement) => {
this._fileReplacements.set(
path.resolve(replacement.replace),
path.resolve(replacement.with)
);
});
}
host.readFile = (fileName) => {
fileName = path.resolve(fileName);
if (this._fileReplacements.has(fileName)) {
const replaceWith = this._fileReplacements.get(fileName)!;
fileName = replaceWith;
}
return oriReadFile(fileName);
};
return host;
}

Expand Down
2 changes: 1 addition & 1 deletion src/configParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface AngularArchitectSubset {
styles: string[];
scripts: string[];
};
configuration: {
configurations: {
[configurationName: string]: AngularArchitectConfig;
};
}
Expand Down

0 comments on commit e92dc20

Please sign in to comment.