Git Product home page Git Product logo

antd-dayjs-vite-plugin's Introduction

npm npm bundle size

A Vite port of antd-dayjs-webpack-plugin. Day.js vite plugin for Ant Design (antd).

Usage

Install via yarn add antd-dayjs-vite-plugin.

In your vite.confg.ts:

import { antdDayjs } from 'antd-dayjs-vite-plugin';

export default defineConfig({
  plugins: [/**/, antdDayjs()],
  // ...
}

Configuration

All options are the same as for antd-dayjs-webpack-plugin. Check the README of antd-dayjs-webpack-plugin for more details.

antd-dayjs-vite-plugin's People

Contributors

nekocode avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

antd-dayjs-vite-plugin's Issues

设置了publicPath之后,路径错误

如果在 vite.config.js 中设置了 base

export default defineConfig({
  base: `/pc-base`,
})

则无法调用此插件。显示
http://localhost:3000/init-dayjs-vite-plugin-entry.js 404 not found

因为此时的正确路径应该是 http://localhost:3000/pc-base/init-dayjs-vite-plugin-entry.js

https://github.com/nekocode/antd-dayjs-vite-plugin/blob/main/src/index.ts#L39

这里是不是要调整一下?

在 webpack 下用 antd-dayjs-webpack-plugin 是不需要设置,但使用正常不报错的。

编译报错

yarn run v1.22.10
$ vite build
vite v2.4.3 building for production...
✓ 1 modules transformed.
[vite]: Rollup failed to resolve import "/init-dayjs-vite-plugin-entry.js" from "index.html".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rollupOptions.external`
error during build:
Error: [vite]: Rollup failed to resolve import "/init-dayjs-vite-plugin-entry.js" from "index.html".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rollupOptions.external`
    at onRollupWarning (D:\code\node_modules\vite\dist\node\chunks\dep-f2b4ca46.js:51734:19)
    at onwarn (D:\code\node_modules\vite\dist\node\chunks\dep-f2b4ca46.js:51519:13)
    at Object.onwarn (D:\code\node_modules\rollup\dist\shared\rollup.js:20470:13)
    at ModuleLoader.handleResolveId (D:\code\node_modules\rollup\dist\shared\rollup.js:19819:26)
    at D:\code\node_modules\rollup\dist\shared\rollup.js:19766:22
    at async Promise.all (index 0)
    at async ModuleLoader.fetchStaticDependencies (D:\code\node_modules\rollup\dist\shared\rollup.js:19764:34)
    at async Promise.all (index 0)
    at async ModuleLoader.fetchModule (D:\code\node_modules\rollup\dist\shared\rollup.js:19740:9)
    at async Promise.all (index 0)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

这个插件在打包之后还需要加载的吗?

搭配使用 vite-plugin-eslint 会有报错

最小启动模型,vite官方react模板+antd+vite-plugin-eslint

app.jsx里随便启用一个DatePicker
vite.config 配置上 eslint plugin之后 会先校验 init-dayjs-vite-plugin-entry.js,访问不存在 导致报错

没有去深究具体插件运行顺序,不确定是哪边的问题

目前解决方案是 init-dayjs-vite-plugin-entry.js 丢进 eslintignore

remove usage of deprecated Vite API

Hi! Thank you for creating this plugin.

We've been using antd-dayjs-vite-plugin and recently updated Vite to v5.
We're getting this warning while running the building the app.

image

Plugin not working/applying in Vite 4. Moment.js still being used (`date4.localeData is not a function`)

I don't know what exactly is going on, but at work I can't even get a simple DatePicker to work. The error occurs when you try to open the date picker

import {DatePicker} from 'antd';
<DatePicker />

Getting this in the console
image
looks like moment is still being used

import fs from 'fs';
import * as dotenv from 'dotenv';
import {defineConfig} from 'vite';
import {chunkSplitPlugin} from 'vite-plugin-chunk-split';
import react from '@vitejs/plugin-react';
import symfonyPlugin from 'vite-plugin-symfony';
import {antdDayjs} from 'antd-dayjs-vite-plugin';
import browserslistToEsbuild from 'browserslist-to-esbuild';

dotenv.config();

export default defineConfig(({command}) => ({
  plugins: [
    chunkSplitPlugin({
      customChunk: ({file}) => {
        // Extract each node_modules package into a separate chunk in "js/npm/(user-)package".
        // Regex taken from: https://github.com/npm/validate-npm-package-name/blob/main/lib/index.js#L3
        const match = file.match(/node_modules\/(?:@([^\/]+?)[\/])?([^\/]+)/);
        if (match) {
          const name = match[1] ? `${match[1]}-${match[2]}` : match[2];
          return `npm/${name}`;
        }
        return null;
      },
    }),
    react(),
    symfonyPlugin({
      viteDevServerHostname: 'localhost',
    }),
    antdDayjs(),
  ],
  base: '/build/',
  build: {
    target: browserslistToEsbuild(),
    outDir: './public/build',
    rollupOptions: {
      input: {
        'public': './assets/public.jsx',
        'portal': './assets/portal.jsx',
        'living-styleguide': './assets/living-styleguide.jsx',
      },
      output: {
        assetFileNames: (assetInfo) => {
          // Place asset in each corresponding folder "build/{img,font,etc.}/*".
          const info = assetInfo.name.split('.');
          let extType = info[info.length - 1];
          if (/png|jpe?g|svg|gif|tiff|bmp|ico/i.test(extType)) {
            extType = 'img';
          } else if (/woff2?|otf|ttf|eot/.test(extType)) {
            extType = 'font';
          }
          return `${extType}/[name].[hash][extname]`;
        },
        chunkFileNames: 'js/[name].[hash].js',
        entryFileNames: 'js/[name].[hash].js',
      },
    },
    manifest: true,
  },
  server: {
    host: '0.0.0.0',
    port: 3000,
    https: {
      // Get certificates if we are not building (CI has no certificates)
      key: command === 'build' ? null : fs.readFileSync('docker/run/certificates/key.pem'),
      cert: command === 'build' ? null : fs.readFileSync('docker/run/certificates/cert.pem'),
    },
    watch: {
      ignored: ['**/tests/**', '**/var/**', '**/vendor/**'],
    },
    origin: `https://${process.env.APP_URL}:3000`,
  },
  // Needed for antd
  css: {
    preprocessorOptions: {
      less: {
        javascriptEnabled: true,
      },
    },
  },
}));

as you can see I do am using your plugin
The only custom thing i can even think about is setting the locale, but i don't think that has anything to do with this issue

import dayjsDeLocale from 'dayjs/locale/de-ch';
import dayjsFrLocale from 'dayjs/locale/fr-ch';
import dayjsItLocale from 'dayjs/locale/it-ch';
import dayjsEnLocale from 'dayjs/locale/en';
import dayjs from 'dayjs';

const locale = document.documentElement.lang ?? 'de';

const dayjsLocales = {
  de: dayjsDeLocale,
  fr: dayjsFrLocale,
  it: dayjsItLocale,
  en: dayjsEnLocale,
};

dayjs.locale(dayjsLocales[locale]);

Could it maybe be because of Vite 4?

{
  "dependencies": {
    "@vitejs/plugin-react": "^3.1.0",
    "antd-dayjs-vite-plugin": "^1.2.2",
    "browserslist-to-esbuild": "^1.2.0",
    "dotenv": "^16.0.3",
    "vite": "^4.1.2",
    "vite-plugin-chunk-split": "^0.4.7",
    "vite-plugin-symfony": "^0.7.5"
  }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.