beyonk-group / svelte-datepicker

A lightweight datepicker written in Svelte
MIT License
143 stars 23 forks source link

Possible temp solution for dayjs import #61

Open Its-Just-Nans opened 2 years ago

Its-Just-Nans commented 2 years ago

Hello, Here is a solution to using this library with vitejs as a bundler working with "vite": "^3.0.7"

Step by step

install @rollup/plugin-replace

npm install @rollup/plugin-replace

change your vite.config.js

import { defineConfig } from "vite";
import relace from "@rollup/plugin-replace";
import { svelte } from "@sveltejs/vite-plugin-svelte";

export default defineConfig({
    plugins: [
        relace({
            preventAssignment: true,
            values: {
                "from 'dayjs": "from 'dayjs/esm",
            },
        }),
        svelte(),
    ],
});

Now you can use the DatePicker

<script>
import DatePicker from "@beyonk/svelte-datepicker/src/components/DatePicker.svelte";
</script>
antony commented 1 year ago

The issue with using dayjs/esm is that it breaks in SSR mode. It's a complex problem to fix.

Where have you experienced this failing?

My thoughts at the moment are to rip out dayjs entirely and use date-fns, since I think dayjs has a fair amount of esm issues.