Skip to content

动态切换全局配置的方法是不是和Plugin-Model有冲突? #12287

Closed Answered by fz6m
DreamParadise asked this question in Q&A
Discussion options

You must be logged in to vote

先这样吧,在项目根目录创建一个 plugin.ts 项目级插件:

// plugin.ts

import { IApi } from '@umijs/max';

export default (api: IApi) => {

  api.onGenerateFiles({
    stage: Infinity,
    fn() {
      api.writeTmpFile({
        path: 'plugin-access/runtime.tsx',
        noPluginDir: true,
        content: `
    import React from 'react';
    import { AccessContext } from './context';
    import useInitialAccess from '@/useInitialAccess';
    
    function Provider(props) {
      const access = useInitialAccess();
    
      return (
        <AccessContext.Provider value={access}>
          { props.children }
        </AccessContext.Provider>
      );
    }
    
    export function accessProvider(container) {

Replies: 2 comments 11 replies

This comment has been hidden.

@DreamParadise

This comment has been hidden.

@fz6m

This comment has been hidden.

@DreamParadise

This comment has been hidden.

@fz6m

This comment has been hidden.

Comment options

You must be logged in to vote
2 replies
@DreamParadise
Comment options

@fz6m
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants