Skip to content

Commit 92c9be4

Browse files
clydinfilipesilva
authored andcommitted
fix(@angular-devkit/build-angular): correctly ignore inline styles during i18n extraction
Stylesheets are not processed during i18n extraction to improve performance and the rules to support them are intentionally not present.
1 parent f209cb5 commit 92c9be4

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed

packages/angular_devkit/build_angular/src/extract-i18n/empty-export-default.js

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
export default function () {
10+
return `export default '';`;
11+
}

packages/angular_devkit/build_angular/src/extract-i18n/index.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,16 @@ export async function execute(
232232
},
233233
});
234234

235-
// Replace all stylesheets with an empty default export
235+
// Replace all stylesheets with empty content
236236
partials.push({
237-
plugins: [
238-
new webpack.NormalModuleReplacementPlugin(
239-
/\.(css|scss|sass|styl|less)$/,
240-
path.join(__dirname, 'empty-export-default.js'),
241-
),
242-
],
237+
module: {
238+
rules: [
239+
{
240+
test: /\.(css|scss|sass|styl|less)$/,
241+
loader: require.resolve('./empty-loader'),
242+
},
243+
],
244+
},
243245
});
244246

245247
return partials;

packages/angular_devkit/build_angular/src/extract-i18n/works_spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,17 @@ describe('Extract i18n Target', () => {
146146
const fullLog = logs.join();
147147
expect(fullLog).toContain('Duplicate messages with id');
148148
});
149+
150+
it('ignores inline styles', async () => {
151+
host.appendToFile('src/app/app.component.html', '<p i18n>i18n test</p>');
152+
host.replaceInFile('src/app/app.component.ts', 'styleUrls', 'styles');
153+
host.replaceInFile('src/app/app.component.ts', './app.component.css', 'h1 { color: green; }');
154+
155+
const run = await architect.scheduleTarget(extractI18nTargetSpec);
156+
157+
// This will fail if a style is processed since the style rules are not included during extraction
158+
await expectAsync(run.result).toBeResolvedTo(jasmine.objectContaining({ success: true }));
159+
160+
await run.stop();
161+
});
149162
});

0 commit comments

Comments
 (0)