forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(@ngtools/webpack): allow .svg files as templates
With directTemplateLoading enabled, components can now use .svg files as templates. For AOT builds, the Angular compiler host now reads .svg files directly when reading component templates. For JIT builds, replaceResources creates a require call that directly uses raw-loader instead of using the loader provided by the current webpack configuration. Closes angular#10567
- Loading branch information
Showing
6 changed files
with
156 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
packages/angular_devkit/build_angular/test/browser/svg_spec_large.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import { runTargetSpec } from '@angular-devkit/architect/testing'; | ||
import { join, normalize, virtualFs } from '@angular-devkit/core'; | ||
import { tap } from 'rxjs/operators'; | ||
import { browserTargetSpec, host, outputPath } from '../utils'; | ||
|
||
describe('Browser Builder allow svg', () => { | ||
|
||
beforeEach(done => host.initialize().toPromise().then(done, done.fail)); | ||
afterEach(done => host.restore().toPromise().then(done, done.fail)); | ||
|
||
it('works with aot', | ||
(done) => { | ||
|
||
const svg = ` | ||
<svg xmlns="http://www.w3.org/2000/svg"> | ||
<text x="20" y="20" font-size="20" fill="red">Hello World</text> | ||
</svg>`; | ||
|
||
host.writeMultipleFiles({ | ||
'./src/app/app.component.svg': svg, | ||
'./src/app/app.component.ts': ` | ||
import { Component } from '@angular/core'; | ||
@Component({ | ||
selector: 'app-root', | ||
templateUrl: './app.component.svg', | ||
styleUrls: [] | ||
}) | ||
export class AppComponent { | ||
title = 'app'; | ||
} | ||
`, | ||
}); | ||
|
||
const overrides = { aot: true }; | ||
|
||
runTargetSpec(host, browserTargetSpec, overrides).pipe( | ||
tap((buildEvent) => expect(buildEvent.success).toBe(true)), | ||
tap(() => { | ||
const content = virtualFs.fileBufferToString( | ||
host.scopedSync().read(join(outputPath, 'main.js')), | ||
); | ||
|
||
expect(content).toContain('":svg:svg"'); | ||
expect(host.scopedSync().exists(normalize('dist/app.component.svg'))) | ||
.toBe(false, 'should not copy app.component.svg to dist'); | ||
}), | ||
).toPromise().then(done, done.fail); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters