svelte-datepicker icon indicating copy to clipboard operation
svelte-datepicker copied to clipboard

Possible temp solution for dayjs import

Open Its-Just-Nans opened this issue 3 years ago • 1 comments

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>

Its-Just-Nans avatar Aug 29 '22 18:08 Its-Just-Nans

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.

antony avatar Apr 10 '23 07:04 antony