@lugia/mega-config

1.3.3 • Public • Published

@lugia/mega-config

Usage

import getUserConfig, {
  watchConfigs,
  unwatchConfigs,
} from '@lugia/mega-config';

// get user config
let config = null;
let userPKG = null;
let returnedWatchConfig = null;
try {
  ({ config, userPKG, watch: returnedWatchConfig } = getUserConfig({
    cwd,
    configFileName: configFile || CONFIG_FILE_NAME,
  }));
  debug(`user config: ${JSON.stringify(config)}`);
} catch (e) {
  console.error(chalk.red(e.message));
  debug(`Get ${CONFIG_FILE_NAME} config failed, watch config and reload`);

  // 监听配置项变更,然后重新执行 dev 逻辑
  watchConfigs({ cwd, configFileName: CONFIG_FILE_NAME }).on(
    'all',
    (event, path) => {
      debug(`[${event}] ${path}, unwatch and reload`);
      bs && bs.active && bs.exit(); // eslint-disable-line
      bs = null;
      unwatchConfigs();
      runDev(opts);
    },
  );
  return;
}

Readme

Keywords

none

Package Sidebar

Install

npm i @lugia/mega-config

Weekly Downloads

19

Version

1.3.3

License

Apache-2.0

Unpacked Size

30.1 kB

Total Files

52

Last publish

Collaborators

  • yssinstitute
  • zenjava
  • sleepyaries
  • grguang
  • szfeng
  • wangcuixia