Skip to content

Commit

Permalink
feat: plugins work in setup
Browse files Browse the repository at this point in the history
Plugins work in setup
  • Loading branch information
xiaohuoni committed Sep 7, 2023
2 parents 1ef3e03 + 61c4a5c commit 28dd5f7
Show file tree
Hide file tree
Showing 16 changed files with 45 additions and 21 deletions.
6 changes: 6 additions & 0 deletions .changeset/chilled-brooms-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@alita/plugins': patch
'alita': patch
---

feat: plugins work in setup
14 changes: 7 additions & 7 deletions packages/alita/src/features/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ export default (api: IApi) => {
});
api.onStart(() => {
if (!api.userConfig.legacy) {
const text =
'[WARN] 为了构建默认快,[email protected]+ 之后移除了默认 legacy 配置,如果你的项目有低版本浏览器兼容,请在配置文件中使用 legacy:{} ';
logger.warn(text);
logger.warn(text);
logger.warn(text);
logger.warn('不想看到这个提示,请在配置文件中增加 legacyBuild:false ');
logger.warn('我们将会在以后的版本中,移除这些提示');
// const text =
// '[WARN] 为了构建默认快,[email protected]+ 之后移除了默认 legacy 配置,如果你的项目有低版本浏览器兼容,请在配置文件中使用 legacy:{} ';
// logger.warn(text);
// logger.warn(text);
// logger.warn(text);
// logger.warn('不想看到这个提示,请在配置文件中增加 legacyBuild:false ');
// logger.warn('我们将会在以后的版本中,移除这些提示');
}
});
};
3 changes: 2 additions & 1 deletion packages/plugins/src/aconsole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export default (api: AlitaApi) => {
});

// only dev or build running
if (!['dev', 'build', 'dev-config', 'preview'].includes(api.name)) return;
if (!['dev', 'build', 'dev-config', 'preview', 'setup'].includes(api.name))
return;

if (aconsole?.console) {
api.addHTMLHeadScripts(() => {
Expand Down
3 changes: 2 additions & 1 deletion packages/plugins/src/antd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ export default (api: AlitaApi) => {
});

// only dev or build running
if (!['dev', 'build', 'dev-config', 'preview'].includes(api.name)) return;
if (!['dev', 'build', 'dev-config', 'preview', 'setup'].includes(api.name))
return;

api.modifyAppData((memo) => {
const version = require(`${pkgPath}/package.json`).version;
Expand Down
3 changes: 2 additions & 1 deletion packages/plugins/src/antdmobile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import { checkAntdMobile } from './utils/checkAntdMobile';
*/
export default (api: AlitaApi) => {
// only dev or build running
if (!['dev', 'build', 'dev-config', 'preview'].includes(api.name)) return;
if (!['dev', 'build', 'dev-config', 'preview', 'setup'].includes(api.name))
return;

// babel-plugin-import
api.addExtraBabelPlugins(() => {
Expand Down
3 changes: 2 additions & 1 deletion packages/plugins/src/classnames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { dirname } from 'path';

export default (api: AlitaApi) => {
// only dev or build running
if (!['dev', 'build', 'dev-config', 'preview'].includes(api.name)) return;
if (!['dev', 'build', 'dev-config', 'preview', 'setup'].includes(api.name))
return;

api.addExtraBabelPlugins(() => {
return [require.resolve('@alita/babel-transform-jsx-class')];
Expand Down
3 changes: 2 additions & 1 deletion packages/plugins/src/dva.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export default (api: AlitaApi) => {
api.addRuntimePluginKey(() => ['dva']);

// only dev or build running
if (!['dev', 'build', 'dev-config', 'preview'].includes(api.name)) return;
if (!['dev', 'build', 'dev-config', 'preview', 'setup'].includes(api.name))
return;

api.modifyAppData((memo) => {
const models = getAllModels(api);
Expand Down
3 changes: 2 additions & 1 deletion packages/plugins/src/hd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export default (api: AlitaApi) => {
enableBy,
});
// only dev or build running
if (!['dev', 'build', 'dev-config', 'preview'].includes(api.name)) return;
if (!['dev', 'build', 'dev-config', 'preview', 'setup'].includes(api.name))
return;

api.modifyDefaultConfig((config) => {
const draftConfig = config;
Expand Down
7 changes: 6 additions & 1 deletion packages/plugins/src/keepalive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ export default (api: AlitaApi) => {
api.addRuntimePluginKey(() => 'getKeepAlive');

// only dev or build running
if (!['dev', 'build', 'dev-config', 'preview'].includes(api.name)) return;
if (
!['dev', 'build', 'dev-config', 'preview', 'setup', 'setup'].includes(
api.name,
)
)
return;

const configStringify = (config: (string | RegExp)[]) => {
return config.map((item) => {
Expand Down
3 changes: 2 additions & 1 deletion packages/plugins/src/mainpath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export default (api: AlitaApi) => {
enableBy: api.EnableBy.config,
});
// only dev or build running
if (!['dev', 'build', 'dev-config', 'preview'].includes(api.name)) return;
if (!['dev', 'build', 'dev-config', 'preview', 'setup'].includes(api.name))
return;

if (api.userConfig.mainPath) {
const mainPath = api.userConfig.mainPath.startsWith('/')
Expand Down
3 changes: 2 additions & 1 deletion packages/plugins/src/max/initial-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import statePlugin from '@umijs/plugins/dist/initial-state';
import { logger } from '@umijs/utils';

export default (api: AlitaApi) => {
if (!['dev', 'build', 'dev-config', 'preview'].includes(api.name)) return;
if (!['dev', 'build', 'dev-config', 'preview', 'setup'].includes(api.name))
return;

api.onStart(() => {
logger.info('Using Initial State Plugin');
Expand Down
3 changes: 2 additions & 1 deletion packages/plugins/src/max/locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import localePlugin from '@umijs/plugins/dist/locale';
import { logger } from '@umijs/utils';

export default (api: AlitaApi) => {
if (!['dev', 'build', 'dev-config', 'preview'].includes(api.name)) return;
if (!['dev', 'build', 'dev-config', 'preview', 'setup'].includes(api.name))
return;

api.onStart(() => {
logger.info('Using Locale Plugin');
Expand Down
3 changes: 2 additions & 1 deletion packages/plugins/src/mobile-layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export default (api: AlitaApi) => {
// 注册runtime配置
api.addRuntimePluginKey(() => ['mobileLayout']);
// only dev or build running
if (!['dev', 'build', 'dev-config', 'preview'].includes(api.name)) return;
if (!['dev', 'build', 'dev-config', 'preview', 'setup'].includes(api.name))
return;

const isMicroApp = api.userConfig.appType === 'micro';

Expand Down
3 changes: 2 additions & 1 deletion packages/plugins/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export default (api: AlitaApi) => {
// enableBy: api.EnableBy.config,
});
// only dev or build running
if (!['dev', 'build', 'dev-config', 'preview'].includes(api.name)) return;
if (!['dev', 'build', 'dev-config', 'preview', 'setup'].includes(api.name))
return;

// umi model 里面不注册
api.describe = () => {};
Expand Down
3 changes: 2 additions & 1 deletion packages/plugins/src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export default (api: AlitaApi) => {
api.addRuntimePluginKey(() => ['request']);

// only dev or build running
if (!['dev', 'build', 'dev-config', 'preview'].includes(api.name)) return;
if (!['dev', 'build', 'dev-config', 'preview', 'setup'].includes(api.name))
return;

// 注册runtime配置
api.addEntryCodeAhead(() => [
Expand Down
3 changes: 2 additions & 1 deletion packages/plugins/src/tabs-layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export default (api: AlitaApi) => {
// 注册runtime配置
api.addRuntimePluginKey(() => ['tabsLayout', 'getCustomTabs']);
// only dev or build running
if (!['dev', 'build', 'dev-config', 'preview'].includes(api.name)) return;
if (!['dev', 'build', 'dev-config', 'preview', 'setup'].includes(api.name))
return;

// 只是为了增加一个 tabsLayout 的配置开关,逻辑在 keepalive 插件中实现
api.onStart(() => {
Expand Down

0 comments on commit 28dd5f7

Please sign in to comment.