npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

umi-plugin-intl

v1.0.0

Published

Umi Plugin for Intl Group Business

Readme

umi-plugin-intl

version license downloads

Umi Plugin for Intl Group Business

Install

$ npm i umi-plugin-intl --save

Usage

Basic Uasge

  1. 在 umi 配置中引用插件:
export default defineConfig({
  plugins: ['umi-plugin-intl'],
})
  1. 在 config 目录下创建模板文件 document.tpl 以下是内容示例:
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Demo Page</title>
  {% if env === 'production' %}
  <link rel="stylesheet" href="{{ assetsPath }}umi.css">
  {% endif %}
</head>
<body>
<div id="{{ config.mountElementId | d('root') }}"></div>

<script src="{{ assetsPath }}umi.js"></script>
</body>
</html>

以上模板会使用 nunjucks 渲染,更多语法请查看官方文档。

Advanced

使用额外的插件配置:

export default defineConfig({
  plugins: ['umi-plugin-intl'],

  pluginIntl: {
    templatePath: 'public/template.tpl',
    renderProps: {
      foo: 'bar',
    }
  },
})

配置项 pluginIntl 定义如下:

| name | desc | required | default | | ------------ | ----------------------------------------------------------------------- | -------- | --------------------- | | templatePath | 模板路径,模板使用 nunjucks 语法 | no | config/document.tpl | | renderProps | 通过 nunjucks 渲染时注入的数据 | no | {} |

renderProps 会默认注入以下数据:

interface IDefaultProps {
  /**
   * 当前的编译环境
   */
  env: 'development' | 'production';
  /**
   * 当前的 umi user config,
   * 从 .umirc 或 config/config 中读取的内容,没有经过 defaultConfig 以及插件的任何处理
   */
  config: Record<string, any>;
  /**
   * 当前项目的 package.json 对象
   */
  pkgInfo: Record<string, any>;
};

Utils API

createMock

创建一个 mock 数据,支持 mockjs 语法,示例:

import { createMock } from 'umi-plugin-intl';

export default {
  // 直接返回数据
  'GET /api/todo/list': createMock({
    success: '@boolean',
    'data|5-10': [{
      id: '@id'
    }]
  }),

  // 通过 callback 返回数据
  // req 是 express 的 Request 对象
  'POST /api/todo/add': createMock(async (req) => {
    return {
      success: true
    };
  }),

  // 读取文件并返回
  'GET /api/todo/file': createMock('./data/data1.json'),

  // 返回 text 数据
  'GET /api/todo/text': createMock(`Hello World`, { dataType: 'text' }),
}

方法定义:

interface IMockOptions {
  /** 是否使用 mockjs 语法,默认 true,仅支持 dataType 为 'json' */
  useMockjs?: boolean;
  /** 返回内容格式,如果是 text,则不支持 mockjs 语法 */
  dataType?: 'json' | 'text';
}

type MockFunc = (req: Request, res: Response) => Promise<void>;

function createMock(callback: (req: Request) => Promise<Record<string, any>>, options?: IMockOptions): MockFunc;
function createMock(filename: string, options?: IMockOptions): MockFunc;
function createMock(data: Record<string, any>, options?: IMockOptions): MockFunc;

关于 mockjs 语法请查看文档:http://mockjs.com/examples.html

LIcense

BSD-3-Clause License