-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(@angular-devkit/build-angular): add option to retain CSS special…
… comments in global styles Prior to this change special CSS comments `/*! comment */` were being removed during minification when using the application builder. This caused tools that ran post build that rely on such comments such as purgeCSS and critters not to function properly. We now provide a `removeSpecialComments` option to enable retention of these comments in global CSS files. Usage example: ```json { "projects": { "my-app": { "architect": { "build": { "builder": "@angular-devkit/build-angular:application", "configurations": { "production": { "optimization": { "styles": { "removeSpecialComments": false } } } } } } } } } ``` Closes: #26432
- Loading branch information
1 parent
adba8be
commit e0b274b
Showing
5 changed files
with
98 additions
and
4 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
File renamed without changes.
79 changes: 79 additions & 0 deletions
79
...gular/src/builders/application/tests/options/optimization-remove-special-comments_spec.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,79 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC 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 { buildApplication } from '../../index'; | ||
import { APPLICATION_BUILDER_INFO, BASE_OPTIONS, describeBuilder } from '../setup'; | ||
|
||
describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => { | ||
describe('Behavior: "removeSpecialComments"', () => { | ||
beforeEach(async () => { | ||
await harness.writeFile( | ||
'src/styles.css', | ||
` | ||
/* normal-comment */ | ||
/*! important-comment */ | ||
div { flex: 1 } | ||
`, | ||
); | ||
}); | ||
|
||
it(`should retain special comments when 'removeSpecialComments' is set to 'false'`, async () => { | ||
harness.useTarget('build', { | ||
...BASE_OPTIONS, | ||
extractLicenses: true, | ||
styles: ['src/styles.css'], | ||
optimization: { | ||
styles: { | ||
removeSpecialComments: false, | ||
}, | ||
}, | ||
}); | ||
|
||
const { result } = await harness.executeOnce(); | ||
expect(result?.success).toBeTrue(); | ||
|
||
harness | ||
.expectFile('dist/browser/styles.css') | ||
.content.toMatch(/\/\*! important-comment \*\/[\s\S]*div{flex:1}/); | ||
}); | ||
|
||
it(`should not retain special comments when 'removeSpecialComments' is set to 'true'`, async () => { | ||
harness.useTarget('build', { | ||
...BASE_OPTIONS, | ||
extractLicenses: true, | ||
styles: ['src/styles.css'], | ||
optimization: { | ||
styles: { | ||
removeSpecialComments: true, | ||
}, | ||
}, | ||
}); | ||
|
||
const { result } = await harness.executeOnce(); | ||
expect(result?.success).toBeTrue(); | ||
|
||
harness.expectFile('dist/browser/styles.css').content.not.toContain('important-comment'); | ||
}); | ||
|
||
it(`should not retain special comments when 'removeSpecialComments' is not set`, async () => { | ||
harness.useTarget('build', { | ||
...BASE_OPTIONS, | ||
extractLicenses: true, | ||
styles: ['src/styles.css'], | ||
optimization: { | ||
styles: {}, | ||
}, | ||
}); | ||
|
||
const { result } = await harness.executeOnce(); | ||
expect(result?.success).toBeTrue(); | ||
|
||
harness.expectFile('dist/browser/styles.css').content.not.toContain('important-comment'); | ||
}); | ||
}); | ||
}); |
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