Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(@schematics/angular): augment universal schematics to import platform-server shims #19869

Merged
merged 1 commit into from Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,6 +1,15 @@
/***************************************************************************************************
* Initialize the server environment - for example, adding DOM built-in types to the global scope.
*
* NOTE:
* This import must come before any imports (direct or transitive) that rely on DOM built-ins being
* available, such as `@angular/elements`.
*/
import '@angular/platform-server/init';

<% if (hasLocalizePackage) { %>/***************************************************************************************************
* Load `$localize` onto the global scope - used if i18n tags appear in Angular templates.
*/
*/
import '@angular/localize/init';

<% } %>import { enableProdMode } from '@angular/core';
Expand Down
8 changes: 8 additions & 0 deletions packages/schematics/angular/universal/index_spec.ts
Expand Up @@ -242,6 +242,14 @@ describe('Universal Schematic', () => {
expect(tree.exists(filePath)).toEqual(true);
});

it(`should add import to '@angular/platform-server/init' in main file`, async () => {
const tree = await schematicRunner.runSchematicAsync('universal', defaultOptions, appTree)
.toPromise();
const filePath = '/projects/bar/src/main.server.ts';
const contents = tree.readContent(filePath);
expect(contents).toContain('import \'@angular/platform-server/init\'');
});

it(`should not add import to '@angular/localize' in main file when it's not a depedency`, async () => {
const tree = await schematicRunner.runSchematicAsync('universal', defaultOptions, appTree)
.toPromise();
Expand Down