Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support umi mfsu #50

Merged
merged 1 commit into from
Jul 1, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 32 additions & 24 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,31 @@ export default (api) => {
stage: -1 * Number.MAX_SAFE_INTEGER,
})

// // 因 keep-alive 的 runtime 部分选择不渲染其 children,可能会丢失默认的用户 rootContainer
// // 此处修复自定义 rootContainer
// // https://github.com/umijs/umi/blob/master/packages/preset-built-in/src/plugins/generateFiles/core/plugin.ts#L23-L27
// const customizedAppPath = getFile({
// base: api.paths.absSrcPath,
// fileNameWithoutExt: 'app',
// type: 'javascript',
// })?.path
// // 因 keep-alive 的 runtime 部分选择不渲染其 children,可能会丢失默认的用户 rootContainer
// // 此处修复自定义 rootContainer
// // https://github.com/umijs/umi/blob/master/packages/preset-built-in/src/plugins/generateFiles/core/plugin.ts#L23-L27
// const customizedAppPath = getFile({
// base: api.paths.absSrcPath,
// fileNameWithoutExt: 'app',
// type: 'javascript',
// })?.path

// if (customizedAppPath) {
// api.addRuntimePlugin({
// fn: () => '@@/plugin-keep-alive/fixCustomizedRuntime',
// stage: -1 * Number.MAX_SAFE_INTEGER + 1,
// })
// if (customizedAppPath) {
// api.addRuntimePlugin({
// fn: () => '@@/plugin-keep-alive/fixCustomizedRuntime',
// stage: -1 * Number.MAX_SAFE_INTEGER + 1,
// })

// api.onGenerateFiles(async () => {
// api.writeTmpFile({
// path: 'plugin-keep-alive/fixCustomizedRuntime.tsx',
// content: utils.Mustache.render(
// readFileSync(join(__dirname, 'fixCustomizedRuntime.tsx.tpl'), 'utf-8'),
// {},
// ),
// })
// })
// }
// api.onGenerateFiles(async () => {
// api.writeTmpFile({
// path: 'plugin-keep-alive/fixCustomizedRuntime.tsx',
// content: utils.Mustache.render(
// readFileSync(join(__dirname, 'fixCustomizedRuntime.tsx.tpl'), 'utf-8'),
// {},
// ),
// })
// })
// }

// Babel Plugin for react-activation
api.modifyBabelOpts((babelOpts) => {
Expand All @@ -42,10 +42,18 @@ export default (api) => {
})

// 生成:export * from 'react-activation'
// TODO: 指明支持的 api,使用上述方式存在 bug https://github.com/guybedford/es-module-lexer/issues/76
// 业务中可 import { KeepAlive } from 'umi'
api.addUmiExports(() => [
{
exportAll: true,
specifiers: [
'KeepAlive',
'useActivate',
'useUnactivate',
'withActivation',
'withAliveScope',
'useAliveController'
],
source: 'react-activation',
},
])
Expand Down