How to use umi-utils - 10 common examples

To help you get started, we’ve selected a few umi-utils 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-test / src / transformers / jsTransformer.js View on Github external
[
      require.resolve('babel-plugin-module-resolver'),
      {
        alias: {
          // Projects don't need to install react, react-dom and enzyme
          react: compatDirname(
            'react/package',
            cwd,
            dirname(require.resolve('react/package.json')),
          ),
          'react-dom': compatDirname(
            'react-dom/package',
            cwd,
            dirname(require.resolve('react-dom/package.json')),
          ),
          enzyme: compatDirname(
            'enzyme/package.json',
            cwd,
            dirname(require.resolve('enzyme/package.json')),
          ),
          'enzyme-adapter-react-16': compatDirname(
            'enzyme-adapter-react-16/package.json',
            cwd,
            dirname(require.resolve('enzyme-adapter-react-16/package.json')),
          ),
        },
      },
      'umi-test',
    ],
  ],
});
github umijs / umi / packages / umi-test / src / transformers / jsTransformer.js View on Github external
require.resolve('@babel/preset-typescript'),
    [
      require.resolve('babel-preset-umi'),
      {
        transformRuntime: false,
        // ...(process.env.TARGETS === 'node' ? { targets: { node: 8 } } : {}),
      },
    ],
  ],
  plugins: [
    [
      require.resolve('babel-plugin-module-resolver'),
      {
        alias: {
          // Projects don't need to install react, react-dom and enzyme
          react: compatDirname(
            'react/package',
            cwd,
            dirname(require.resolve('react/package.json')),
          ),
          'react-dom': compatDirname(
            'react-dom/package',
            cwd,
            dirname(require.resolve('react-dom/package.json')),
          ),
          enzyme: compatDirname(
            'enzyme/package.json',
            cwd,
            dirname(require.resolve('enzyme/package.json')),
          ),
          'enzyme-adapter-react-16': compatDirname(
            'enzyme-adapter-react-16/package.json',
github ddnlink / ddn / packages / ddn-test / src / transformers / jsTransformer.js View on Github external
// ...(process.env.TARGETS === 'node' ? { targets: { node: 8 } } : {}),
      },
    ],
  ],
  plugins: [
    [
      require.resolve('babel-plugin-module-resolver'),
      {
        alias: {
          // Projects don't need to install react, react-dom and enzyme
          react: compatDirname(
            'react/package',
            cwd,
            dirname(require.resolve('react/package.json')),
          ),
          'react-dom': compatDirname(
            'react-dom/package',
            cwd,
            dirname(require.resolve('react-dom/package.json')),
          ),
          enzyme: compatDirname(
            'enzyme/package.json',
            cwd,
            dirname(require.resolve('enzyme/package.json')),
          ),
          'enzyme-adapter-react-16': compatDirname(
            'enzyme-adapter-react-16/package.json',
            cwd,
            dirname(require.resolve('enzyme-adapter-react-16/package.json')),
          ),
        },
      },
github umijs / umi / packages / umi-test / src / transformers / jsTransformer.js View on Github external
// ...(process.env.TARGETS === 'node' ? { targets: { node: 8 } } : {}),
      },
    ],
  ],
  plugins: [
    [
      require.resolve('babel-plugin-module-resolver'),
      {
        alias: {
          // Projects don't need to install react, react-dom and enzyme
          react: compatDirname(
            'react/package',
            cwd,
            dirname(require.resolve('react/package.json')),
          ),
          'react-dom': compatDirname(
            'react-dom/package',
            cwd,
            dirname(require.resolve('react-dom/package.json')),
          ),
          enzyme: compatDirname(
            'enzyme/package.json',
            cwd,
            dirname(require.resolve('enzyme/package.json')),
          ),
          'enzyme-adapter-react-16': compatDirname(
            'enzyme-adapter-react-16/package.json',
            cwd,
            dirname(require.resolve('enzyme-adapter-react-16/package.json')),
          ),
        },
      },
github ddnlink / ddn / packages / ddn-test / src / transformers / jsTransformer.js View on Github external
[
      require.resolve('babel-plugin-module-resolver'),
      {
        alias: {
          // Projects don't need to install react, react-dom and enzyme
          react: compatDirname(
            'react/package',
            cwd,
            dirname(require.resolve('react/package.json')),
          ),
          'react-dom': compatDirname(
            'react-dom/package',
            cwd,
            dirname(require.resolve('react-dom/package.json')),
          ),
          enzyme: compatDirname(
            'enzyme/package.json',
            cwd,
            dirname(require.resolve('enzyme/package.json')),
          ),
          'enzyme-adapter-react-16': compatDirname(
            'enzyme-adapter-react-16/package.json',
            cwd,
            dirname(require.resolve('enzyme-adapter-react-16/package.json')),
          ),
        },
      },
      'ddn-test',
    ],
  ],
});
github ddnlink / ddn / packages / ddn-test / src / transformers / jsTransformer.js View on Github external
require.resolve('@babel/preset-typescript'),
    [
      require.resolve('babel-preset-umi'),
      {
        transformRuntime: false,
        // ...(process.env.TARGETS === 'node' ? { targets: { node: 8 } } : {}),
      },
    ],
  ],
  plugins: [
    [
      require.resolve('babel-plugin-module-resolver'),
      {
        alias: {
          // Projects don't need to install react, react-dom and enzyme
          react: compatDirname(
            'react/package',
            cwd,
            dirname(require.resolve('react/package.json')),
          ),
          'react-dom': compatDirname(
            'react-dom/package',
            cwd,
            dirname(require.resolve('react-dom/package.json')),
          ),
          enzyme: compatDirname(
            'enzyme/package.json',
            cwd,
            dirname(require.resolve('enzyme/package.json')),
          ),
          'enzyme-adapter-react-16': compatDirname(
            'enzyme-adapter-react-16/package.json',
github umijs / umi / packages / umi-build-dev / src / Service.js View on Github external
init() {
    // load env
    this.loadEnv();

    // init plugins
    this.initPlugins();

    // reload user config
    const userConfig = new UserConfig(this);
    const config = userConfig.getConfig({ force: true });
    mergeConfig(this.config, config);
    this.userConfig = userConfig;
    if (config.browserslist) {
      deprecate('config.browserslist', 'use config.targets instead');
    }
    debug('got user config');
    debug(this.config);

    // assign user's outputPath config to paths object
    if (config.outputPath) {
      const { paths } = this;
      paths.outputPath = config.outputPath;
      paths.absOutputPath = join(paths.cwd, config.outputPath);
    }
    debug('got paths');
    debug(this.paths);
  }
github umijs / umi / packages / umi-build-dev / src / plugins / commands / block / download.js View on Github external
export async function parseGitUrl(url, closeFastGithub) {
  const args = GitUrlParse(url);
  const { ref, filepath, resource, full_name: fullName } = args;
  const fastGithub = await getFastGithub();

  // 如果是 github 并且 autoFastGithub =true 使用
  // 因为自动转化只支持 github 也可以需要关掉
  const repo =
    resource === 'github.com' && !closeFastGithub
      ? args.toString().replace(`${resource}`, fastGithub)
      : args.toString();

  return {
    repo: urlAddGit(repo),
    branch: ref || 'master',
    path: `/${filepath}`,
    id: `${resource}/${fullName}`, // 唯一标识一个 git 仓库
  };
}
github umijs / umi / packages / umi-build-dev / src / plugins / commands / block / addBlock.ts View on Github external
subBlocks.map((block: string) => {
          const subBlockPath = join(ctx.templateTmpDirPath, block);
          debug(`subBlockPath: ${subBlockPath}`);
          return new BlockGenerator(args._.slice(2), {
            sourcePath: subBlockPath,
            path: isPageBlock ? generator.path : join(generator.path, generator.blockFolderName),
            // eslint-disable-next-line
            blockName: getNameFromPkg(require(join(subBlockPath, 'package.json'))),
            isPageBlock: false,
            dryRun,
            env: {
              cwd: api.cwd,
            },
            routes: api.config.routes,
            resolved: winPath(__dirname),
          }).run();
        }),
      );
github umijs / umi / packages / umi-build-dev / src / plugins / commands / block / ui / util.ts View on Github external
.map((fileName: string) => {
      const status = fs.statSync(join(path, fileName));
      // 是文件夹 并且不已 . 开头, 且最深三层
      if (status.isDirectory() && fileName.indexOf('.') !== 0 && depth < 3) {
        const absPath = winPath(join(path, fileName));
        const absPagePath = winPath(join(parentPath, fileName));
        const children = getFolderTreeData(absPath, absPagePath, depth + 1);
        if (children && children.length > 0) {
          return {
            key: absPagePath,
            title: fileName,
            value: absPagePath,
            children,
          };
        }
        return { title: fileName, value: absPagePath, key: absPagePath };
      }
      return undefined;
    })
    .filter(obj => obj);