File tree Expand file tree Collapse file tree
packages/ngtools/webpack/src/ivy Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -74,8 +74,16 @@ export function angularWebpackLoader(
7474 }
7575
7676 // Write the declaration file in the target dir
77- if ( result . declaration ) {
78- fs . writeFileSync ( this . resourcePath . replace ( '.ts' , '.d.ts' ) , result . declaration ) ;
77+ if ( result . declaration && fileEmitter . compilerOptions . declaration ) {
78+ let target = this . resourcePath . replace ( '.ts' , '.d.ts' ) ;
79+ if ( fileEmitter . compilerOptions . declarationDir ) {
80+ if ( ! fileEmitter . compilerOptions . baseUrl ) {
81+ throw new Error ( 'When declarationDir is specified, baseUrl is required as well' ) ;
82+ }
83+ const relDir = path . relative ( fileEmitter . compilerOptions . baseUrl , target ) ;
84+ target = path . join ( fileEmitter . compilerOptions . declarationDir , relDir ) ;
85+ }
86+ fs . writeFileSync ( target , result . declaration ) ;
7987 }
8088 callback ( undefined , resultContent , resultMap ) ;
8189 } )
Original file line number Diff line number Diff line change @@ -85,6 +85,7 @@ export class AngularWebpackPlugin {
8585 private readonly requiredFilesToEmit = new Set < string > ( ) ;
8686 private readonly requiredFilesToEmitCache = new Map < string , EmitFileResult | undefined > ( ) ;
8787 private readonly fileEmitHistory = new Map < string , FileEmitHistoryItem > ( ) ;
88+ private compilerOptions ! : CompilerOptions ;
8889
8990 constructor ( options : Partial < AngularWebpackPluginOptions > = { } ) {
9091 this . pluginOptions = {
@@ -186,6 +187,7 @@ export class AngularWebpackPlugin {
186187
187188 // Setup and read TypeScript and Angular compiler configuration
188189 const { compilerOptions, rootNames, errors } = this . loadConfiguration ( ) ;
190+ this . compilerOptions = compilerOptions ;
189191
190192 // Create diagnostics reporter and report configuration file errors
191193 const diagnosticsReporter = createDiagnosticsReporter ( compilation , ( diagnostic ) =>
@@ -320,7 +322,7 @@ export class AngularWebpackPlugin {
320322 private registerWithCompilation ( compilation : Compilation ) {
321323 let fileEmitters = compilationFileEmitters . get ( compilation ) ;
322324 if ( ! fileEmitters ) {
323- fileEmitters = new FileEmitterCollection ( ) ;
325+ fileEmitters = new FileEmitterCollection ( this . compilerOptions ) ;
324326 compilationFileEmitters . set ( compilation , fileEmitters ) ;
325327 compilation . compiler . webpack . NormalModule . getCompilationHooks ( compilation ) . loader . tap (
326328 PLUGIN_NAME ,
Original file line number Diff line number Diff line change 66 * found in the LICENSE file at https://angular.dev/license
77 */
88
9+ import { CompilerOptions } from 'typescript' ;
10+
911export const AngularPluginSymbol : unique symbol = Symbol . for ( '@ngtools/webpack[angular-compiler]' ) ;
1012
1113export interface EmitFileResult {
@@ -37,6 +39,8 @@ export class FileEmitterRegistration {
3739export class FileEmitterCollection {
3840 #registrations: FileEmitterRegistration [ ] = [ ] ;
3941
42+ constructor ( public readonly compilerOptions : CompilerOptions ) { }
43+
4044 register ( ) : FileEmitterRegistration {
4145 const registration = new FileEmitterRegistration ( ) ;
4246 this . #registrations. push ( registration ) ;
You can’t perform that action at this time.
0 commit comments