Skip to content

Commit 1e7cf9b

Browse files
clydinhansl
authored andcommitted
feat(@ngtools/webpack): support directly loading component templates
1 parent b626ca7 commit 1e7cf9b

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

packages/ngtools/webpack/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ The loader works with webpack plugin to compile your TypeScript. It's important
4343
* `sourceMap`. Optional. Include sourcemaps.
4444
* `compilerOptions`. Optional. Override options in `tsconfig.json`.
4545
* `contextElementDependencyConstructor`. Optional. Set to `require('webpack/lib/dependencies/ContextElementDependency')` if you are having `No module factory available for dependency type: ContextElementDependency` errors.
46+
* `directTemplateLoading`. Optional. Causes the plugin to load component templates (HTML) directly from the filesystem. This is more efficient if only using the `raw-loader` to load component templates. Do not enable this option if additional loaders are configured for component templates.
4647

4748
## Features
4849
The benefits and ability of using [`@ngtools/webpack`](https://www.npmjs.com/~ngtools) standalone from the Angular CLI as presented in [Stephen Fluin's Angular CLI talk](https://youtu.be/uBRK6cTr4Vk?t=6m45s) at Angular Connect 2016:

packages/ngtools/webpack/src/angular_compiler_plugin.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ export interface AngularCompilerPluginOptions {
103103
platform?: PLATFORM;
104104
nameLazyFiles?: boolean;
105105
logger?: logging.Logger;
106+
directTemplateLoading?: boolean;
106107

107108
// added to the list of lazy routes
108109
additionalLazyModules?: { [module: string]: string };
@@ -627,6 +628,7 @@ export class AngularCompilerPlugin {
627628
this._basePath,
628629
host,
629630
watchMode,
631+
this._options.directTemplateLoading,
630632
);
631633

632634
// Create and set a new WebpackResourceLoader.

packages/ngtools/webpack/src/compiler_host.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export class WebpackCompilerHost implements ts.CompilerHost {
4646
basePath: string,
4747
host: virtualFs.Host,
4848
private readonly cacheSourceFiles: boolean,
49+
private readonly directTemplateLoading = false,
4950
) {
5051
this._syncHost = new virtualFs.SyncDelegateHost(host);
5152
this._memoryHost = new virtualFs.SyncDelegateHost(new virtualFs.SimpleMemoryHost());
@@ -326,6 +327,10 @@ export class WebpackCompilerHost implements ts.CompilerHost {
326327
}
327328

328329
readResource(fileName: string) {
330+
if (this.directTemplateLoading && fileName.endsWith('.html')) {
331+
return this.readFile(fileName);
332+
}
333+
329334
if (this._resourceLoader) {
330335
// These paths are meant to be used by the loader so we must denormalize them.
331336
const denormalizedFileName = this.denormalizePath(normalize(fileName));

0 commit comments

Comments
 (0)