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 🙏

© 2024 – Pkg Stats / Ryan Hefner

wtbx-vite-antd-locale-import

v1.0.3

Published

通過配置動態產出對應的 dayjs 與 antd date-picker/locale 的語系 import 語法 (更: package.json 更新)

Downloads

2

Readme

wtbx-vite-antd-locale-import

通過配置動態產出對應的 dayjs 與 antd date-picker/locale 的語系 import 語法

配置

// vite.config.ts
import { defineConfig } from 'vite'

export default defineConfig({
  plugins: [
    // 泛型可以傳入 union 來做 key 限制
    antdLocaleImport<string>({
      // 只有一個參數 locales
      locales: {
        // locales 下的每個 key 對應後續方法的唯一參 key
        zh_TW: {
          // 配置 dayjs 取出的 locole 檔名
          dayjs: 'zh-tw',
          // 配置 antd 取出的 locale 檔名
          antd: "zh_TW",
        },
        // 同其他
        en: {
          dayjs: 'en',
          antd: "en_US",
        },
      },
    }),
  ],
})


// vite-env.d.ts
declare module '~import-antd-locales' {
  import type { ImportAntdLocales } from 'wtbx-vite-antd-locale-import'
  // 泛型傳入同 vite.config.ts 的泛型一致,一樣可以用 union 做限制
  export default importAntdLocales = ImportAntdLocales<string>
}

使用

import importAntdLocales from '~import-antd-locales'

export async function updateLocale(locale: string) {
  // importAntdLocales 內部僅對你傳入的 key 去匹配然後 import 對應的語系檔
  // 假設 locale 傳入 zh_TW,那麼會 import 這些 js 檔
  // return Promise.all([
  //     對應配置的 antd
  //     import('antd/es/date-picker/locale/zh_TW'),
  
  //     對應配置的 antd
  //     import('antd/locale/zh_TW'),
  
  //     對應配置的 dayjs
  //     import('dayjs/locale/zh-tw'),
  //   ])
  const [antdDatePickerLocaleModule, antdLocaleModule] = await importAntdLocales(locale)
  // ... do something
}