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

fix(umi-build-dev): config change don't update service's config #585

Merged
merged 2 commits into from
Jun 1, 2018

Conversation

sorrycc
Copy link
Member

@sorrycc sorrycc commented Jun 1, 2018

No description provided.

@coveralls
Copy link

coveralls commented Jun 1, 2018

Pull Request Test Coverage Report for Build 575

  • 0 of 5 (0.0%) changed or added relevant lines in 2 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-0.03%) to 21.737%

Changes Missing Coverage Covered Lines Changed/Added Lines %
packages/umi-build-dev/src/UserConfig.js 0 2 0.0%
packages/umi-build-dev/src/Service.js 0 3 0.0%
Files with Coverage Reduction New Missed Lines %
packages/umi-build-dev/src/Service.js 1 0.0%
Totals Coverage Status
Change from base Build 571: -0.03%
Covered Lines: 519
Relevant Lines: 2618

💛 - Coveralls

@sorrycc
Copy link
Member Author

sorrycc commented Jun 1, 2018

补充下 testcase:

plugin

import assert from 'assert';

export default (api) => {
  const { config } = api.service;
  assert(config.singular === undefined, 'modifyConfig 修改的配置在方法外不生效');

  let modified = false;

  api.register('modifyConfig', ({ memo }) => {
    return {
      ...memo,
      singular: true,
    };
  });

  api.register('onStart', () => {
    assert(config.ctoken === 1);
    assert(api.service.config.ctoken === 1);
    assert(config.singular === true);
    assert(api.service.config.singular === true);
  });

  api.register('modifyConfigPlugins', ({ memo }) => {
    memo.push(api => ({
      name: 'ctoken',
      onChange(c) {
        assert(c.ctoken === 2);
        assert(api.service.config.ctoken === 2);
        modified = true;
        api.service.filesGenerator.rebuild();
      },
    }));
    return memo;
  });

  api.register('modifyEntryFile', ({ memo }) => {
    if (modified) {
      assert(config.ctoken === 2);
      assert(api.service.config.ctoken === 2);
    } else {
      assert(config.ctoken === 1);
      assert(api.service.config.ctoken === 1);
    }
    assert(config.singular === true);
    assert(api.service.config.singular === true);
    return memo;
  })
}

.umirc.js

export default {
  plugins: [
    './plugin',
  ],
  ctoken: 1,
};

启动后修改 ctoken 为 2。

@sorrycc sorrycc merged commit fcb1de2 into master Jun 1, 2018
@sorrycc sorrycc deleted the fix/config branch June 1, 2018 07:51
sorrycc added a commit that referenced this pull request Jun 23, 2022
* docs: 📝 for env-variable

* Update docs/docs/guides/env-variables.md

Co-authored-by: Yuanlin Lin <im.yuanlinlin@gmail.com>

* Update docs/docs/guides/env-variables.md

* Update docs/docs/guides/env-variables.md

Co-authored-by: pshu <pishu.spf@antfin.com>
Co-authored-by: Yuanlin Lin <im.yuanlinlin@gmail.com>
Co-authored-by: chencheng (云谦) <sorrycc@gmail.com>
xierenyuan pushed a commit to xierenyuan/umi that referenced this pull request Jun 23, 2022
* docs: 📝 for env-variable

* Update docs/docs/guides/env-variables.md

Co-authored-by: Yuanlin Lin <im.yuanlinlin@gmail.com>

* Update docs/docs/guides/env-variables.md

* Update docs/docs/guides/env-variables.md

Co-authored-by: pshu <pishu.spf@antfin.com>
Co-authored-by: Yuanlin Lin <im.yuanlinlin@gmail.com>
Co-authored-by: chencheng (云谦) <sorrycc@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants