Skip to content

Commit 5256699

Browse files
committed
refactor(@ngtools/webpack): remove implicit dependency on raw-loader
When JIT mode and `directTemplateLoading` were enabled, the plugin would reference the `raw-loader` dependency. This dependency was not mentioned in the `package.json` and is also now deprecated. An internal `direct-resource` loader is now used instead which removes the usage of the implicit dependency.
1 parent 098ff0d commit 5256699

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
export const DirectAngularResourceLoaderPath = __filename;
10+
11+
export default function (content: string) {
12+
return `export default ${JSON.stringify(content)};`;
13+
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
import * as ts from 'typescript';
10+
import { DirectAngularResourceLoaderPath } from '../loaders/direct-resource';
1011
import { InlineAngularResourceLoaderPath } from '../loaders/inline-resource';
1112

1213
export function replaceResources(
@@ -167,7 +168,10 @@ function visitComponentMetadata(
167168
return undefined;
168169

169170
case 'templateUrl':
170-
const url = getResourceUrl(node.initializer, directTemplateLoading ? '!raw-loader!' : '');
171+
const url = getResourceUrl(
172+
node.initializer,
173+
directTemplateLoading ? `!${DirectAngularResourceLoaderPath}!` : '',
174+
);
171175
if (!url) {
172176
return node;
173177
}

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import { tags } from '@angular-devkit/core';
1010
import * as ts from 'typescript';
11+
import { DirectAngularResourceLoaderPath } from '../loaders/direct-resource';
1112
import { replaceResources } from './replace_resources';
1213
import { createTypescriptContext, transformTypescript } from './spec_helpers';
1314

@@ -52,7 +53,7 @@ describe('@ngtools/webpack transformers', () => {
5253
`;
5354
const output = tags.stripIndent`
5455
import { __decorate } from "tslib";
55-
import __NG_CLI_RESOURCE__0 from "!raw-loader!./app.component.html";
56+
import __NG_CLI_RESOURCE__0 from "!${DirectAngularResourceLoaderPath}!./app.component.html";
5657
import __NG_CLI_RESOURCE__1 from "./app.component.css";
5758
import __NG_CLI_RESOURCE__2 from "./app.component.2.css";
5859
import { Component } from '@angular/core';
@@ -102,7 +103,7 @@ describe('@ngtools/webpack transformers', () => {
102103
AppComponent = tslib_1.__decorate([
103104
core_1.Component({
104105
selector: 'app-root',
105-
template: require("!raw-loader!./app.component.html").default,
106+
template: require("!${DirectAngularResourceLoaderPath}!./app.component.html").default,
106107
styles: [require("./app.component.css").default, require("./app.component.2.css").default] }) ], AppComponent);
107108
exports.AppComponent = AppComponent;
108109
`;
@@ -166,7 +167,7 @@ describe('@ngtools/webpack transformers', () => {
166167
`;
167168
const output = tags.stripIndent`
168169
import { __decorate } from "tslib";
169-
import __NG_CLI_RESOURCE__0 from "!raw-loader!./app.component.svg";
170+
import __NG_CLI_RESOURCE__0 from "!${DirectAngularResourceLoaderPath}!./app.component.svg";
170171
import { Component } from '@angular/core';
171172
let AppComponent = class AppComponent {
172173
constructor() {
@@ -202,7 +203,7 @@ describe('@ngtools/webpack transformers', () => {
202203
`;
203204
const output = tags.stripIndent`
204205
import { __decorate } from "tslib";
205-
import __NG_CLI_RESOURCE__0 from "!raw-loader!./app.component.html";
206+
import __NG_CLI_RESOURCE__0 from "!${DirectAngularResourceLoaderPath}!./app.component.html";
206207
import __NG_CLI_RESOURCE__1 from "./app.component.css";
207208
import { Component } from '@angular/core';
208209
@@ -240,7 +241,7 @@ describe('@ngtools/webpack transformers', () => {
240241
`;
241242
const output = tags.stripIndent`
242243
import { __decorate } from "tslib";
243-
import __NG_CLI_RESOURCE__0 from "!raw-loader!./app.component.html";
244+
import __NG_CLI_RESOURCE__0 from "!${DirectAngularResourceLoaderPath}!./app.component.html";
244245
import __NG_CLI_RESOURCE__1 from "data:text/css;charset=utf-8;base64,YSB7IGNvbG9yOiByZWQgfQ==";
245246
import { Component } from '@angular/core';
246247
@@ -284,7 +285,7 @@ describe('@ngtools/webpack transformers', () => {
284285
`;
285286
const output = `
286287
import { __decorate } from "tslib";
287-
import __NG_CLI_RESOURCE__0 from "!raw-loader!./app.component.html";
288+
import __NG_CLI_RESOURCE__0 from "!${DirectAngularResourceLoaderPath}!./app.component.html";
288289
import __NG_CLI_RESOURCE__1 from "./app.component.css";
289290
import __NG_CLI_RESOURCE__2 from "./app.component.2.css";
290291
@@ -323,7 +324,7 @@ describe('@ngtools/webpack transformers', () => {
323324
`;
324325
const output = tags.stripIndent`
325326
import { __decorate } from "tslib";
326-
import __NG_CLI_RESOURCE__0 from "!raw-loader!./app.component.html";
327+
import __NG_CLI_RESOURCE__0 from "!${DirectAngularResourceLoaderPath}!./app.component.html";
327328
import __NG_CLI_RESOURCE__1 from "./app.component.css";
328329
import __NG_CLI_RESOURCE__2 from "./app.component.2.css";
329330
import { Component as NgComponent } from '@angular/core';
@@ -366,7 +367,7 @@ describe('@ngtools/webpack transformers', () => {
366367
`;
367368
const output = tags.stripIndent`
368369
import { __decorate } from "tslib";
369-
import __NG_CLI_RESOURCE__0 from "!raw-loader!./app.component.html";
370+
import __NG_CLI_RESOURCE__0 from "!${DirectAngularResourceLoaderPath}!./app.component.html";
370371
import __NG_CLI_RESOURCE__1 from "./app.component.css";
371372
import __NG_CLI_RESOURCE__2 from "./app.component.2.css";
372373
@@ -411,7 +412,7 @@ describe('@ngtools/webpack transformers', () => {
411412

412413
const output = tags.stripIndent`
413414
import { __decorate } from "tslib";
414-
import __NG_CLI_RESOURCE__0 from "!raw-loader!./app.component.html";
415+
import __NG_CLI_RESOURCE__0 from "!${DirectAngularResourceLoaderPath}!./app.component.html";
415416
import __NG_CLI_RESOURCE__1 from "./app.component.css";
416417
417418
import { Component } from '@angular/core';

0 commit comments

Comments
 (0)