How to use umi-core - 10 common examples

To help you get started, we’ve selected a few umi-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github umijs / umi / packages / umi-build-dev / src / plugins / commands / generate / generators / page / index.js View on Github external
join(paths.absPagesPath, `${path}.${jsxExt}`),
        context,
      );
      this.fs.copyTpl(
        this.templatePath('page.css.tpl'),
        join(paths.absPagesPath, `${path}.${cssExt}`),
        context,
      );

      if (config.routes) {
        writeNewRoute(
          {
            path: `/${path === 'index' ? '' : path}`,
            component: `./${path}`,
          },
          getConfigFile(cwd),
          paths.absSrcPath,
        );
        // log.warn(
        //   `You should config the routes in config.routes manunally since ${chalk.red(
        //     'config.routes',
        //   )} exists`,
        // );
        console.log();
      }
    }
  };
github umijs / umi / packages / umi / src / isUmiUIEnable.js View on Github external
export default function(cwd) {
  registerBabel(cwd);
  const config = getUserConfig({ cwd });

  if (config.ssr) return false;

  if (process.env.BIGFISH_COMPAT) {
    if (config.appType !== 'console') return false;
    if (config.deployMode === 'chair') return false;
  }

  const pkgFile = join(cwd, 'package.json');
  const pkg = existsSync(pkgFile) ? JSON.parse(readFileSync(pkgFile, 'utf-8')) : {};

  // disable if react is lower than 16
  const reactVersion = getDep(pkg, 'react');
  if (reactVersion) {
    const reactPkgFile = join(cwd, 'node_modules', 'react', 'package.json');
    const reactPkg = existsSync(reactPkgFile)
github umijs / umi / packages / umi-build-dev / src / UserConfig.js View on Github external
getConfig(opts = {}) {
    const { paths, cwd } = this.service;
    const { force, setConfig } = opts;
    const defaultConfig = this.service.applyPlugins('modifyDefaultConfig', {
      initialValue: {},
    });

    const file = getConfigFile(cwd);
    this.file = file;
    if (!file) {
      return defaultConfig;
    }

    // 强制读取,不走 require 缓存
    if (force) {
      cleanConfigRequireCache(cwd);
    }

    let config = null;
    const relativeFile = file.replace(`${paths.cwd}/`, '');
    this.relativeFile = relativeFile;

    const onError = (e, file) => {
      const msg = `配置文件 "${file.replace(`${paths.cwd}/`, '')}" 解析出错,请检查语法。
github umijs / umi / packages / umi-serve / bin / umi-serve.js View on Github external
const { winPath } = require('umi-utils');
const getUserConfig = require('umi-core/lib/getUserConfig');
const getPaths = require('umi-core/lib/getPaths');
const boxen = require('boxen');
const clipboardy = require('clipboardy');
const os = require('os');
const port = process.env.PORT || 8001;
const cwd = process.cwd();

let paths;

// 获取 config 之前先注册一遍
registerBabel();

const config = getUserConfig.default({ cwd });
paths = getPaths.default({ cwd, config });

const app = express();

// Gzip support
app.use(
  compression({
    filter: (req, res) => {
      if (req.headers['x-no-compression']) {
        // don't compress responses with this request header
        return false;
      }
      // fallback to standard filter function
      return compression.filter(req, res);
    },
  }),
);
github umijs / umi / packages / umi-build-dev / src / UserConfig.js View on Github external
getConfig(opts = {}) {
    const { paths, cwd } = this.service;
    const { force, setConfig } = opts;
    const defaultConfig = this.service.applyPlugins('modifyDefaultConfig', {
      initialValue: {},
    });

    const file = getConfigFile(cwd);
    this.file = file;
    if (!file) {
      return defaultConfig;
    }

    // 强制读取,不走 require 缓存
    if (force) {
      cleanConfigRequireCache(cwd);
    }

    let config = null;
    const relativeFile = file.replace(`${paths.cwd}/`, '');
    this.relativeFile = relativeFile;

    const onError = (e, file) => {
      const msg = `配置文件 "${file.replace(`${paths.cwd}/`, '')}" 解析出错,请检查语法。
\r\n${e.toString()}`;
      this.printError(msg);
      throw e;
    };

    config = getConfigByConfigFile(file, {
      defaultConfig,
      onError,
github umijs / umi / packages / umi-serve / bin / umi-serve.js View on Github external
const compression = require('compression');
const { winPath } = require('umi-utils');
const getUserConfig = require('umi-core/lib/getUserConfig');
const getPaths = require('umi-core/lib/getPaths');
const boxen = require('boxen');
const clipboardy = require('clipboardy');
const os = require('os');
const port = process.env.PORT || 8001;
const cwd = process.cwd();

let paths;

// 获取 config 之前先注册一遍
registerBabel();

const config = getUserConfig.default({ cwd });
paths = getPaths.default({ cwd, config });

const app = express();

// Gzip support
app.use(
  compression({
    filter: (req, res) => {
      if (req.headers['x-no-compression']) {
        // don't compress responses with this request header
        return false;
      }
      // fallback to standard filter function
      return compression.filter(req, res);
    },
  }),
github umijs / umi / packages / umi-build-dev / src / UserConfig.js View on Github external
if (force) {
      cleanConfigRequireCache(cwd);
    }

    let config = null;
    const relativeFile = file.replace(`${paths.cwd}/`, '');
    this.relativeFile = relativeFile;

    const onError = (e, file) => {
      const msg = `配置文件 "${file.replace(`${paths.cwd}/`, '')}" 解析出错,请检查语法。
\r\n${e.toString()}`;
      this.printError(msg);
      throw e;
    };

    config = getConfigByConfigFile(file, {
      defaultConfig,
      onError,
    });

    config = this.service.applyPlugins('_modifyConfig', {
      initialValue: config,
    });

    // Validate
    for (const plugin of this.plugins) {
      const { name, validate } = plugin;
      if (config[name] && validate) {
        try {
          plugin.validate.call({ cwd }, config[name]);
        } catch (e) {
          // 校验出错后要把值设到缓存的 config 里,确保 watch 判断时才能拿到正确的值
github umijs / umi / packages / umi / src / isUmiUIEnable.js View on Github external
export default function(cwd) {
  registerBabel(cwd);
  const config = getUserConfig({ cwd });

  if (config.ssr) return false;

  if (process.env.BIGFISH_COMPAT) {
    if (config.appType !== 'console') return false;
    if (config.deployMode === 'chair') return false;
  }

  const pkgFile = join(cwd, 'package.json');
  const pkg = existsSync(pkgFile) ? JSON.parse(readFileSync(pkgFile, 'utf-8')) : {};

  // disable if react is lower than 16
  const reactVersion = getDep(pkg, 'react');
  if (reactVersion) {
    const reactPkgFile = join(cwd, 'node_modules', 'react', 'package.json');
github umijs / umi / packages / umi-build-dev / src / registerBabel.js View on Github external
function initFiles(cwd) {
  files = uniq(files.concat(getConfigPaths(cwd)));
}
github umijs / umi / packages / umi-build-dev / src / UserConfig.js View on Github external
watchConfigs(handler) {
    const { cwd } = this.service;
    const watcher = this.watch('CONFIG_FILES', getConfigPaths(cwd));
    if (watcher) {
      watcher.on('all', handler);
    }
  }
}