Skip to content

Commit

Permalink
feat: check bundler before apply styled babel plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
PeachScript committed Nov 13, 2023
1 parent f3641ad commit 47fa9e0
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/core/src/service/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export class Service {
mpa?: {
entry?: { [key: string]: string }[];
};
bundler?: string;
[key: string]: any;
} = {};
args: yParser.Arguments = { _: [], $0: '' };
Expand Down
3 changes: 3 additions & 0 deletions packages/plugins/src/styled-components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export default (api: IApi) => {
// dev: displayName
// prod: minify
api.modifyConfig((memo) => {
// only apply babel plugin in webpack and vite
if (!['webpack', 'vite'].includes(api.appData.bundler)) return memo;

Check failure on line 24 in packages/plugins/src/styled-components.ts

View workflow job for this annotation

GitHub Actions / build (14.x, ubuntu-latest)

Argument of type 'string | undefined' is not assignable to parameter of type 'string'.

Check failure on line 24 in packages/plugins/src/styled-components.ts

View workflow job for this annotation

GitHub Actions / build (16.x, ubuntu-latest)

Argument of type 'string | undefined' is not assignable to parameter of type 'string'.

Check failure on line 24 in packages/plugins/src/styled-components.ts

View workflow job for this annotation

GitHub Actions / build (18.x, ubuntu-latest)

Argument of type 'string | undefined' is not assignable to parameter of type 'string'.

const isProd = api.env === 'production';
const pluginConfig = {
// https://github.com/styled-components/babel-plugin-styled-components/blob/f8e9fb480d1645be8be797d73e49686bdf98975b/src/utils/options.js#L11
Expand Down
1 change: 1 addition & 0 deletions packages/preset-umi/src/features/appData/appData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export default (api: IApi) => {
memo.globalJS = globalJS;
memo.overridesCSS = overridesCSS;
memo.globalLoading = globalLoading;
memo.bundler = 'webpack';

const gitDir = findGitDir(api.paths.cwd);
if (gitDir) {
Expand Down
6 changes: 6 additions & 0 deletions packages/preset-umi/src/features/vite/vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ export default (api: IApi) => {
enableBy: api.EnableBy.config,
});

api.modifyAppData((memo) => {
memo.bundler = 'vite';

return memo;
});

api.modifyConfig((memo) => {
// like vite, use to pre-bundling dependencies in vite mode
memo.alias['@fs'] = api.cwd;
Expand Down

0 comments on commit 47fa9e0

Please sign in to comment.