Skip to content

Commit

Permalink
feat: add styled-components plugin (umijs#9970)
Browse files Browse the repository at this point in the history
  • Loading branch information
sorrycc authored Dec 7, 2022
1 parent c2326c1 commit d4ea2e7
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 145 deletions.
1 change: 1 addition & 0 deletions packages/max/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default () => {
require.resolve('@umijs/plugins/dist/moment2dayjs'),
require.resolve('@umijs/plugins/dist/qiankun'),
require.resolve('@umijs/plugins/dist/request'),
require.resolve('@umijs/plugins/dist/styled-components'),
require.resolve('@umijs/plugins/dist/tailwindcss'),
require.resolve('@umijs/plugins/dist/valtio'),
require.resolve('./plugins/maxAlias'),
Expand Down
1 change: 1 addition & 0 deletions packages/plugins/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"react-intl": "3.12.1",
"react-redux": "^8.0.2",
"redux": "^4.2.0",
"styled-components": "6.0.0-beta.6",
"warning": "^4.0.3"
},
"devDependencies": {
Expand Down
26 changes: 26 additions & 0 deletions packages/plugins/src/styled-components.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { dirname } from 'path';
import { IApi } from 'umi';

export default (api: IApi) => {
api.describe({
key: 'styledComponents',
config: {
schema(Joi) {
return Joi.object();
},
},
enableBy: api.EnableBy.config,
});

// reexports with types
const libPath = dirname(require.resolve('styled-components/package'));
api.onGenerateFiles(() => {
api.writeTmpFile({
path: 'index.tsx',
content: `
import styled, { ThemeProvider, createGlobalStyle, css, keyframes, StyleSheetManager, useTheme } from '${libPath}';
export { styled, ThemeProvider, createGlobalStyle, css, keyframes, StyleSheetManager, useTheme };
`,
});
});
};
Loading

0 comments on commit d4ea2e7

Please sign in to comment.