Skip to content

Commit 098ff0d

Browse files
committed
refactor(@ngtools/webpack): move internal loaders into a subdirectory
The source file for the internal inline resource loader is moved into a `loaders` subdirectory for better code organization. The need to call `require.resolve` is also removed from the consumers of this loader.
1 parent 492c879 commit 098ff0d

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

packages/ngtools/webpack/src/inline-data-loader.ts renamed to packages/ngtools/webpack/src/loaders/inline-resource.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
import type { Compilation, LoaderContext } from 'webpack';
1010

11+
export const InlineAngularResourceLoaderPath = __filename;
12+
1113
export const InlineAngularResourceSymbol = Symbol('@ngtools/webpack[angular-resource]');
1214

1315
export interface CompilationWithInlineAngularResource extends Compilation {

packages/ngtools/webpack/src/resource_loader.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ import { createHash } from 'crypto';
1010
import * as path from 'path';
1111
import * as vm from 'vm';
1212
import type { Asset, Compilation } from 'webpack';
13+
import { normalizePath } from './ivy/paths';
1314
import {
1415
CompilationWithInlineAngularResource,
16+
InlineAngularResourceLoaderPath,
1517
InlineAngularResourceSymbol,
16-
} from './inline-data-loader';
17-
import { normalizePath } from './ivy/paths';
18+
} from './loaders/inline-resource';
1819

1920
interface CompilationOutput {
2021
content: string;
@@ -33,7 +34,7 @@ export class WebpackResourceLoader {
3334
private modifiedResources = new Set<string>();
3435
private outputPathCounter = 1;
3536

36-
private readonly inlineDataLoaderPath = require.resolve('./inline-data-loader');
37+
private readonly inlineDataLoaderPath = InlineAngularResourceLoaderPath;
3738

3839
constructor(shouldCache: boolean) {
3940
if (shouldCache) {

packages/ngtools/webpack/src/transformers/replace_resources.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
*/
88

99
import * as ts from 'typescript';
10-
11-
const inlineDataLoaderPath = require.resolve('../inline-data-loader');
10+
import { InlineAngularResourceLoaderPath } from '../loaders/inline-resource';
1211

1312
export function replaceResources(
1413
shouldTransform: (fileName: string) => boolean,
@@ -208,7 +207,7 @@ function visitComponentMetadata(
208207
} else if (inlineStyleFileExtension) {
209208
const data = Buffer.from(node.text).toString('base64');
210209
const containingFile = node.getSourceFile().fileName;
211-
url = `${containingFile}.${inlineStyleFileExtension}!=!${inlineDataLoaderPath}?data=${encodeURIComponent(
210+
url = `${containingFile}.${inlineStyleFileExtension}!=!${InlineAngularResourceLoaderPath}?data=${encodeURIComponent(
212211
data,
213212
)}!${containingFile}`;
214213
} else {

0 commit comments

Comments
 (0)