Skip to content

Commit beb7070

Browse files
alan-agius4Keen Yee Liau
authored andcommitted
feat(@schematics/angular): introduce Ivy libraries for development
Since `NGCC` is non incremental and in library projects we have the original TS sources we don't need to build a library using the `VE` and transform it using `NGCC`. Instead we can build the library using `NGTSC` (Ivy) directly as this enables faster incremental compilations and a better development experience. Libraries now have a `production` configuration, which enabled `VE` compilations. As it is not recommended to publish NGTSC (Ivy) built libraries to NPM repositories, since Ivy libraries are not backwards compatible with the legacy View Engine.
1 parent 2ed70bb commit beb7070

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

packages/schematics/angular/library/files/tsconfig.lib.json.template

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
"annotateForClosureCompiler": true,
1616
"skipTemplateCodegen": true,
1717
"strictMetadataEmit": true,
18-
"fullTemplateTypeCheck": true,
19-
"strictInjectionParameters": true,
2018
"enableResourceInlining": true
2119
},
2220
"exclude": [
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "./tsconfig.lib.json",
3+
"angularCompilerOptions": {
4+
"enableIvy": false
5+
}
6+
}

packages/schematics/angular/library/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ function addDependenciesToPackageJson() {
124124
};
125125
}
126126

127-
function addAppToWorkspaceFile(
127+
function addLibToWorkspaceFile(
128128
options: LibraryOptions,
129129
projectRoot: string,
130130
projectName: string,
@@ -147,6 +147,11 @@ function addAppToWorkspaceFile(
147147
tsConfig: `${projectRoot}/tsconfig.lib.json`,
148148
project: `${projectRoot}/ng-package.json`,
149149
},
150+
configurations: {
151+
production: {
152+
tsConfig: `${projectRoot}/tsconfig.lib.prod.json`,
153+
},
154+
},
150155
},
151156
test: {
152157
builder: Builders.Karma,
@@ -199,7 +204,6 @@ export default function (options: LibraryOptions): Rule {
199204
const folderName = `${scopeFolder}${strings.dasherize(options.name)}`;
200205
const projectRoot = join(normalize(newProjectRoot), folderName);
201206
const distRoot = `dist/${folderName}`;
202-
203207
const sourceDir = `${projectRoot}/src/lib`;
204208

205209
const templateSource = apply(url('./files'), [
@@ -219,7 +223,7 @@ export default function (options: LibraryOptions): Rule {
219223

220224
return chain([
221225
mergeWith(templateSource),
222-
addAppToWorkspaceFile(options, projectRoot, projectName),
226+
addLibToWorkspaceFile(options, projectRoot, projectName),
223227
options.skipPackageJson ? noop() : addDependenciesToPackageJson(),
224228
options.skipTsConfig ? noop() : updateTsConfig(packageName, distRoot),
225229
schematic('module', {

packages/schematics/angular/library/index_spec.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ describe('Library Schematic', () => {
4949
'/projects/foo/package.json',
5050
'/projects/foo/README.md',
5151
'/projects/foo/tslint.json',
52+
'/projects/foo/tsconfig.lib.json',
53+
'/projects/foo/tsconfig.lib.prod.json',
5254
'/projects/foo/src/test.ts',
5355
'/projects/foo/src/my-index.ts',
5456
'/projects/foo/src/lib/foo.module.ts',
@@ -132,7 +134,7 @@ describe('Library Schematic', () => {
132134
});
133135

134136
it('should handle a pascalCasedName', async () => {
135-
const options = {...defaultOptions, name: 'pascalCasedName'};
137+
const options = { ...defaultOptions, name: 'pascalCasedName' };
136138
const tree = await schematicRunner.runSchematicAsync('library', options, workspaceTree).toPromise();
137139
const config = getJsonFileContent(tree, '/angular.json');
138140
const project = config.projects.pascalCasedName;
@@ -317,4 +319,12 @@ describe('Library Schematic', () => {
317319
const specTsConfig = JSON.parse(tree.readContent('/foo/tsconfig.spec.json'));
318320
expect(specTsConfig.extends).toEqual('../tsconfig.json');
319321
});
322+
323+
it(`should add 'production' configuration`, async () => {
324+
const tree = await schematicRunner.runSchematicAsync('library', defaultOptions, workspaceTree)
325+
.toPromise();
326+
327+
const workspace = JSON.parse(tree.readContent('/angular.json'));
328+
expect(workspace.projects.foo.architect.build.configurations.production).toBeDefined();
329+
});
320330
});

0 commit comments

Comments
 (0)