Skip to content

Commit

Permalink
feat(@ngtools/webpack): support directly loading component templates
Browse files Browse the repository at this point in the history
  • Loading branch information
clydin authored and hansl committed Nov 18, 2018
1 parent b626ca7 commit 1e7cf9b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/ngtools/webpack/README.md
Expand Up @@ -43,6 +43,7 @@ The loader works with webpack plugin to compile your TypeScript. It's important
* `sourceMap`. Optional. Include sourcemaps.
* `compilerOptions`. Optional. Override options in `tsconfig.json`.
* `contextElementDependencyConstructor`. Optional. Set to `require('webpack/lib/dependencies/ContextElementDependency')` if you are having `No module factory available for dependency type: ContextElementDependency` errors.
* `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.

## Features
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:
Expand Down
2 changes: 2 additions & 0 deletions packages/ngtools/webpack/src/angular_compiler_plugin.ts
Expand Up @@ -103,6 +103,7 @@ export interface AngularCompilerPluginOptions {
platform?: PLATFORM;
nameLazyFiles?: boolean;
logger?: logging.Logger;
directTemplateLoading?: boolean;

// added to the list of lazy routes
additionalLazyModules?: { [module: string]: string };
Expand Down Expand Up @@ -627,6 +628,7 @@ export class AngularCompilerPlugin {
this._basePath,
host,
watchMode,
this._options.directTemplateLoading,
);

// Create and set a new WebpackResourceLoader.
Expand Down
5 changes: 5 additions & 0 deletions packages/ngtools/webpack/src/compiler_host.ts
Expand Up @@ -46,6 +46,7 @@ export class WebpackCompilerHost implements ts.CompilerHost {
basePath: string,
host: virtualFs.Host,
private readonly cacheSourceFiles: boolean,
private readonly directTemplateLoading = false,
) {
this._syncHost = new virtualFs.SyncDelegateHost(host);
this._memoryHost = new virtualFs.SyncDelegateHost(new virtualFs.SimpleMemoryHost());
Expand Down Expand Up @@ -326,6 +327,10 @@ export class WebpackCompilerHost implements ts.CompilerHost {
}

readResource(fileName: string) {
if (this.directTemplateLoading && fileName.endsWith('.html')) {
return this.readFile(fileName);
}

if (this._resourceLoader) {
// These paths are meant to be used by the loader so we must denormalize them.
const denormalizedFileName = this.denormalizePath(normalize(fileName));
Expand Down

0 comments on commit 1e7cf9b

Please sign in to comment.