skip to Main Content

I have a working Laravel project with Tailwind CSS
I have also used Flowbite Datepicker using CDN to include the datepicker JavaScript.

The project is working fine and the date-picker is showing nicely.
But when I run the npm run prod to minify the project the date-picker dropdown is not showing correctly.

Included the images and code.

Kindly help.

<script src="https://cdnjs.cloudflare.com/ajax/libs/flowbite/1.6.3/datepicker.min.js"></script>

<div class="relative">
    <div class="absolute inset-y-0 left-0 flex items-center pl-3 pointer-events-none">
        <svg ....</svg>
    </div>
    <input id="date" datepicker datepicker-autohide datepicker-format="dd/mm/yyyy" 
    name="date" type="text" readonly="readonly" required autofocus class="form-input 
    shadow-outline-gray text-sm pl-10 w-full @error('date') bg-red-500 @enderror" placeholder="Select Date">
</div>

Image while in DEV
enter image description here

Image while in Production
enter image description here

webpack.mix.js

const mix = require('laravel-mix');

mix
  .js('resources/js/app.js', 'public/js')
  .postCss('resources/css/app.css', 'public/css', [
    require('postcss-import'),
    require('tailwindcss'),
    require('postcss-nested'),
    require('autoprefixer'),
  ]);

if (mix.inProduction()) {
  mix
    .version();
}

2

Answers


  1. Chosen as BEST ANSWER

    As I need an urgent workaround for the production environment and found no other option other than downloading the datepicker.min.js and pasting the code under the script tag in the blade file.

    Now on running "npm run prod" the CSS classes mentioned in the JS is also included while minifying.

    The above workaround is Working fine.

    Waiting for other better solutions. Thanks.


  2. Of course, since the element is rendered in the DOM, the postcss and vite (laravel-mix in your case) watchers are not aware of the classes you are demanding, so in production (minified css) it will never display correctly.

    try to put this above you calendar code, then, run npm run build

    <div class="hidden">
        <div class="days">
            <div class="days-of-week grid grid-cols-7 mb-1 dow block flex-1 leading-9 border-0 rounded-lg cursor-default text-center text-gray-900 font-semibold text-sm"></div>
            <div class="datepicker-grid w-64 grid grid-cols-7 block flex-1 leading-9 border-0 rounded-lg cursor-default text-center text-gray-900 font-semibold text-sm h-6 leading-6 text-sm font-medium text-gray-500 dark:text-gray-400"></div>
        </div>
        <div class="calendar-weeks">
            <div class="days-of-week flex"><span class="dow h-6 leading-6 text-sm font-medium text-gray-500 dark:text-gray-400"></span></div>
            <div class="weeks week block flex-1 leading-9 border-0 rounded-lg cursor-default text-center text-gray-900 font-semibold text-sm"></div>
        </div>
    </div>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search