Skip to content

Commit

Permalink
Merge pull request #585 from umijs/fix/config
Browse files Browse the repository at this point in the history
fix(umi-build-dev): config change don't update service's config
  • Loading branch information
sorrycc authored Jun 1, 2018
2 parents b1204c5 + 8df074e commit fcb1de2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/umi-build-dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"lodash.isequal": "^4.5.0",
"lodash.remove": "^4.7.0",
"mkdirp": "^0.5.1",
"object-assign": "^4.1.1",
"path-is-absolute": "^1.0.1",
"postcss-plugin-px2rem": "^0.7.0",
"preact": "^8.2.5",
Expand Down
3 changes: 3 additions & 0 deletions packages/umi-build-dev/src/Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import getWebpackRCConfig, {
} from 'af-webpack/getUserConfig';
import { clearConsole } from 'af-webpack/react-dev-utils';
import chalk from 'chalk';
import assign from 'object-assign';
import getPaths from './getPaths';
import getRouteConfig from './routes/getRouteConfig';
import registerBabel from './registerBabel';
Expand Down Expand Up @@ -81,6 +82,7 @@ export default class Service {
const userConfig = new UserConfig(this);
try {
this.config = userConfig.getConfig({ force: true });
assign(this._initialConfig, this.config);
} catch (e) {
console.error(chalk.red(e.message));
debug('Get config failed, watch config and reload');
Expand Down Expand Up @@ -224,6 +226,7 @@ export default class Service {
console.error(chalk.red(e.message));
process.exit(1);
}
this._initialConfig = config;
this.config = new Proxy(config, {
set: (target, name, value) => {
target[name] = value;
Expand Down
3 changes: 3 additions & 0 deletions packages/umi-build-dev/src/UserConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,12 @@ class UserConfig {

const oldConfig = clone(this.config);
this.config = newConfig;

for (const plugin of this.plugins) {
const { name } = plugin;
if (!isEqual(newConfig[name], oldConfig[name])) {
this.service._initialConfig[name] = newConfig[name];
this.service.config[name] = newConfig[name];
if (plugin.onChange) {
plugin.onChange(newConfig);
}
Expand Down

0 comments on commit fcb1de2

Please sign in to comment.