fix(react): generate apps/libs using Emotion CSS with valid .babelrc files (#5336)

This commit is contained in:
Jack Hsu 2021-04-13 12:04:31 -04:00 committed by GitHub
parent 159bc9986b
commit a51d19ff8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 2 deletions

View File

@ -184,6 +184,25 @@ describe('app', () => {
).toContain('Welcome to my-app'); ).toContain('Welcome to my-app');
}); });
it.each`
style
${'styled-components'}
${'styled-jsx'}
${'@emotion/styled'}
`(
'should generate valid .babelrc JSON config for CSS-in-JS solutions',
async ({ style }) => {
await applicationGenerator(appTree, {
...schema,
style,
});
expect(() => {
JSON.parse(appTree.read(`apps/my-app/.babelrc`).toString());
}).not.toThrow();
}
);
describe('--style scss', () => { describe('--style scss', () => {
it('should generate scss styles', async () => { it('should generate scss styles', async () => {
await applicationGenerator(appTree, { ...schema, style: 'scss' }); await applicationGenerator(appTree, { ...schema, style: 'scss' });

View File

@ -4,13 +4,13 @@
"@nrwl/react/babel", { "@nrwl/react/babel", {
"runtime": "automatic", "runtime": "automatic",
"useBuiltIns": "usage" "useBuiltIns": "usage"
<% if (style === '@emotion/styled') { %>,"importSource": "@emotion/react" }<% } %> <% if (style === '@emotion/styled') { %>,"importSource": "@emotion/react"<% } %>
} }
] ]
], ],
"plugins": [ "plugins": [
<% if (style === 'styled-components') { %>["styled-components", { "pure": true, "ssr": true }]<% } %> <% if (style === 'styled-components') { %>["styled-components", { "pure": true, "ssr": true }]<% } %>
<% if (style === 'styled-jsx') { %>"styled-jsx/babel"<% } %> <% if (style === 'styled-jsx') { %>"styled-jsx/babel"<% } %>
<% if (style === '@emotion/styled') { %>,"@emotion/babel-plugin"<% } %> <% if (style === '@emotion/styled') { %>"@emotion/babel-plugin"<% } %>
] ]
} }

View File

@ -614,4 +614,24 @@ describe('lib', () => {
).not.toBeDefined(); ).not.toBeDefined();
}); });
}); });
it.each`
style
${'styled-components'}
${'styled-jsx'}
${'@emotion/styled'}
`(
'should generate valid .babelrc JSON config for CSS-in-JS solutions',
async ({ style }) => {
await libraryGenerator(appTree, {
...defaultSchema,
style,
name: 'myLib',
});
expect(() => {
JSON.parse(appTree.read(`libs/my-lib/.babelrc`).toString());
}).not.toThrow();
}
);
}); });