-
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): support specifying stylesheet la…
…nguage for inline component styles A new build option named `inlineStyleLanguage` has been introduced that will allow a project to define the stylesheet language used in an application's inline component styles. Inline component styles are styles defined via the `styles` property within the Angular `Component` decorator. Both JIT and AOT mode are supported. However, JIT mode requires that inline styles only be string literals (compile-time partial evaluation is not supported in JIT mode). Currently supported language options are: `CSS` (default), `Sass`, `SCSS`, and `Less`. If the option is not specified, `CSS` will be used and enables existing projects to continue to function as expected.
- Loading branch information
Showing
9 changed files
with
199 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
110 changes: 110 additions & 0 deletions
110
...ages/angular_devkit/build_angular/src/browser/tests/options/inline-style-language_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,110 @@ | ||
/** | ||
* @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 { buildWebpackBrowser } from '../../index'; | ||
import { InlineStyleLanguage } from '../../schema'; | ||
import { BASE_OPTIONS, BROWSER_BUILDER_INFO, describeBuilder } from '../setup'; | ||
|
||
describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => { | ||
describe('Option: "inlineStyleLanguage"', () => { | ||
beforeEach(async () => { | ||
// Setup application component with inline style property | ||
await harness.modifyFile('src/app/app.component.ts', (content) => { | ||
return content | ||
.replace('styleUrls', 'styles') | ||
.replace('./app.component.css', '__STYLE_MARKER__'); | ||
}); | ||
}); | ||
|
||
for (const aot of [true, false]) { | ||
describe(`[${aot ? 'AOT' : 'JIT'}]`, () => { | ||
it('supports SCSS inline component styles when set to "scss"', async () => { | ||
harness.useTarget('build', { | ||
...BASE_OPTIONS, | ||
inlineStyleLanguage: InlineStyleLanguage.Scss, | ||
aot, | ||
}); | ||
|
||
await harness.modifyFile('src/app/app.component.ts', (content) => | ||
content.replace( | ||
'__STYLE_MARKER__', | ||
'$primary-color: green;\\nh1 { color: $primary-color; }', | ||
), | ||
); | ||
|
||
const { result } = await harness.executeOnce(); | ||
|
||
expect(result?.success).toBe(true); | ||
harness.expectFile('dist/main.js').content.toContain('color: green'); | ||
}); | ||
|
||
it('supports Sass inline component styles when set to "sass"', async () => { | ||
harness.useTarget('build', { | ||
...BASE_OPTIONS, | ||
inlineStyleLanguage: InlineStyleLanguage.Sass, | ||
aot, | ||
}); | ||
|
||
await harness.modifyFile('src/app/app.component.ts', (content) => | ||
content.replace( | ||
'__STYLE_MARKER__', | ||
'$primary-color: green\\nh1\\n\\tcolor: $primary-color', | ||
), | ||
); | ||
|
||
const { result } = await harness.executeOnce(); | ||
|
||
expect(result?.success).toBe(true); | ||
harness.expectFile('dist/main.js').content.toContain('color: green'); | ||
}); | ||
|
||
// Stylus currently does not function due to the sourcemap logic within the `stylus-loader` | ||
// which tries to read each stylesheet directly from disk. In this case, each stylesheet is | ||
// virtual and cannot be read from disk. This issue affects data URIs in general. | ||
// xit('supports Stylus inline component styles when set to "stylus"', async () => { | ||
// harness.useTarget('build', { | ||
// ...BASE_OPTIONS, | ||
// inlineStyleLanguage: InlineStyleLanguage.Stylus, | ||
// aot, | ||
// }); | ||
|
||
// await harness.modifyFile('src/app/app.component.ts', (content) => | ||
// content.replace( | ||
// '__STYLE_MARKER__', | ||
// '$primary-color = green;\\nh1 { color: $primary-color; }', | ||
// ), | ||
// ); | ||
|
||
// const { result } = await harness.executeOnce(); | ||
|
||
// expect(result?.success).toBe(true); | ||
// harness.expectFile('dist/main.js').content.toContain('color: green'); | ||
// }); | ||
|
||
it('supports Less inline component styles when set to "less"', async () => { | ||
harness.useTarget('build', { | ||
...BASE_OPTIONS, | ||
inlineStyleLanguage: InlineStyleLanguage.Less, | ||
aot, | ||
}); | ||
|
||
await harness.modifyFile('src/app/app.component.ts', (content) => | ||
content.replace( | ||
'__STYLE_MARKER__', | ||
'@primary-color: green;\\nh1 { color: @primary-color; }', | ||
), | ||
); | ||
|
||
const { result } = await harness.executeOnce(); | ||
|
||
expect(result?.success).toBe(true); | ||
harness.expectFile('dist/main.js').content.toContain('color: green'); | ||
}); | ||
}); | ||
} | ||
}); | ||
}); |
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
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