-
Notifications
You must be signed in to change notification settings - Fork 12k
feat(@angular-devkit/build-angular): enable font inlining optimizations #18926
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some minor comments
packages/angular_devkit/build_angular/src/browser/specs/optimization-fonts_spec.ts
Outdated
Show resolved
Hide resolved
packages/angular_devkit/build_angular/src/browser/specs/optimization-fonts_spec.ts
Outdated
Show resolved
Hide resolved
packages/angular_devkit/build_angular/src/utils/index-file/inline-fonts.ts
Outdated
Show resolved
Hide resolved
packages/angular_devkit/build_angular/src/utils/index-file/inline-fonts.ts
Outdated
Show resolved
Hide resolved
packages/angular_devkit/build_angular/src/utils/index-file/inline-fonts.ts
Outdated
Show resolved
Hide resolved
packages/angular_devkit/build_angular/src/utils/index-file/inline-fonts.ts
Outdated
Show resolved
Hide resolved
packages/angular_devkit/build_angular/src/utils/index-file/inline-fonts_spec.ts
Outdated
Show resolved
Hide resolved
fonts: FontsClass, | ||
}; | ||
|
||
export function normalizeOptimization(optimization: OptimizationUnion = false): NormalizeOptimizationOptions { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not exactly sure what the default value here means - isn't the default
in the schema true
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strictly speaking the default is defined in the schema which is false
. But in the typings these are still marked as optional.
packages/angular_devkit/build_angular/src/utils/process-bundle.ts
Outdated
Show resolved
Hide resolved
This is the base functionality needed to inline Google fonts and Icons in HTML. The processor does a couple of things: 1. When support for older devices is needed where woff2 is not supported it will inline definitions for both woff1 and woff2 2. Will remove comments and whitespaces when it's `minifyInlinedCSS` is enabled. 3. Cache responses so to resuse the font response during watch mode. Note: this is still an internal implementation which users cannot leverage just yet.
With this change we inline Google fonts and icons in the index html file when optimization is enabled. **Before** ```html <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons"> ``` **After** ```html <style> @font-face { font-family: 'Material Icons'; font-style: normal; font-weight: 400; src: url(https://fonts.gstatic.com/s/materialicons/v55/flUhRq6tzZclQEJ-Vdg-IuiaDsNcIhQ8tQ.woff2) format('woff2'); } .material-icons { font-family: 'Material Icons'; font-weight: normal; font-style: normal; font-size: 24px; line-height: 1; letter-spacing: normal; text-transform: none; display: inline-block; white-space: nowrap; word-wrap: normal; direction: ltr; } </style> ``` To opt-out of this feature set `optimization.fonts: false` or `optimization.fonts.inline: false` in the browser builder options. Example: ```js "configurations": { "production": { "fileReplacements": [ { "replace": "src/environments/environment.ts", "with": "src/environments/environment.prod.ts" } ], "optimization": { "fonts": false }, ``` More information about the motivation for this feature can be found: #18730 Note: internet access is required during the build for this optimization to work.
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
With this change we inline Google fonts and icons in the index html file when optimization is enabled.
Before
After
To opt-out of this feature set
optimization.fonts: false
oroptimization.fonts.inline: false
in the browser builder options.Example:
More information about the motivation for this feature can be found: #18730
Note: internet access is required during the build for this optimization to work.