I am facing an issue with the Tailwind Flowbite Datepicker dropdown UI when running "npm run prod" for minification. The class is not being added during minification on the npm

I have successfully integrated a Laravel project with Tailwind CSS. I have also implemented the Flowbite Datepicker using a CDN to include the necessary JavaScript.

Initially, everything was working fine and the date-picker was displaying correctly. However, after running 'npm run prod' to minify the project, the date-picker dropdown is not appearing as expected.

I have attached both images as well as the code snippet below. Any assistance would be greatly appreciated.

<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 in Development: https://i.sstatic.net/rFjpW.jpg

Image in Production: https://i.sstatic.net/tuxA6.jpg

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();
}

Answer №1

Indeed, as the element is rendered within the DOM, both postcss and vite (or laravel-mix in your scenario) watchers are unable to recognize the classes you require. As a result, when it comes to production (minified css), the display will never be correct.

Consider placing the following code snippet above your calendar code and then execute 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>

Edit.

To ensure best practices and facilitate changes in processing files with vite and tailwindcss classes, add:

'./resources/js/**/*.js',

to your tailwind.cofig.js file. That's all!

Answer №2

Encountered a similar problem and discovered that I had forgotten to include the flowbite.min.css file as instructed in the documentation.

Answer №3

Due to the urgent need for a solution in the production environment, I had to resort to downloading the datepicker.min.js and inserting the code under the script tag in the blade file as there were no other viable options available.

After running "npm run prod," I noticed that the CSS classes mentioned in the JS were also included during minification.

This workaround has proven to be effective and is working smoothly.

I am still open to exploring alternative solutions if any better ones exist. Thank you.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Retrieve Data from MySQL Database Using ExpressJS Pool Connection

I am relatively new to ExpressJS. I am encountering an issue where console.log is working fine and I can see the data in the terminal when I make a call. However, the data is not being returned as a response. Even after using console.log and return stateme ...

The input box is not properly filled with the complete string using protractor sendKeys

[HTTP] --> POST /wd/hub/session/ffcd7072-9f96-45cb-a61d-ec53fc696b56/element/0.9513211246393813-32/value {"value":["1","0","0","0","1"],"text":"10001"} My JavaScript code snippet: this.zipcode = element(by.model('personalInfo.zipcode')); t ...

Changing the story in javascript

I am trying to customize the legend to display the following values: 80+ (or 80%+) 75-80 70-75 65-70 60-65 55-50 <50% While I have organized the list in descending order, I seem to be facing an issue with getting the less than symbol to function corr ...

Choosing the perfect item with the help of a material's GridList

I've developed a react-mobx application using Material-UI, and the code structure is similar to this: render() { // defining some constants return ( <div> <img src={selectedPhoto} alt={'image title'} /> < ...

Attempting to execute `npx create-react-app my-app` with a different npm configuration

Currently utilizing a MacBook Pro. Recently installed nvm. The node version is set to 16.17.0, while npm -v and nix -v displaying 8.15.0. Encountering failure when executing npx create-react-app my-app, with the log indicating... info using <a href="/ ...

I'm curious as to why the size of the Preact npm package listing is showing over 1MB when it's advertised as only 3kb

Recently, I've been exploring the possibility of using Preact for creating embeddable and distributable widgets. One of the key selling points highlighted all over is its promised tiny build size of just 3kb, as stated on their official website. Howe ...

Powershell error occurs when custom arguments are used with NPM

I'm attempting to run an npm script with a personalized argument: "publish-local": "ng build $PROJECT && cd dist/$PROJECT && npm publish --registry=http://my.local.npm.registry" Here is how I am trying to execute it from the command prompt: PROJECT ...

Issue with Bootstrap 5 Carousel not transitioning between slides

I am trying to add a carousel to my webpage, but it seems like it's not sliding and only displaying the first image. I've double-checked my code and everything else from Bootstrap works fine. Here's the snippet of code I'm using: < ...

How do I incorporate global typings when adding type definitions to an npm module?

Suppose I create a node module called m. Later on, I decide to enhance it with Typescript typings. Luckily, the module only exports a single function, so the m.d.ts file is as follows: /// <reference path="./typings/globals/node/index.d.ts" /> decl ...

What is the best way to customize the appearance of Image tags located inside SVGs, whether they are in separate files or embedded within the code

I am developing a custom SVG editor application and facing an issue with implementing a highlighted effect when an <image> element is clicked. I have successfully accomplished this for other elements like <circle> by adjusting attributes such a ...

What is the best way to apply a texture to a triangle using three.js?

I've been able to add textures to cubes, spheres, and other primitives in a scene I created. However, when it comes to adding a texture to a simple triangle, I'm encountering difficulties. Below is my attempt at achieving this: var texture=TH ...

Is there a way to specify that npm should be installed in the Dockerfile being built from Centos:7?

I'm tasked with using an existing Dockerfile that creates a docker image from Centos 7. (The first line in the Dockerfile is 'FROM centos:7.') I need to run 'npm install' and 'npm run' commands inside the containers runn ...

Creating a PDF from dynamic HTML and transferring it to an AWS S3 bucket without the need to download the PDF

We have created a web application using React JS where we attempted to generate a PDF. Instead of downloading or opening the PDF in a new window, our goal is to directly upload it to an AWS S3 bucket. We have researched and tried various samples but have n ...

Testcafe Live is currently not active

Operating on OsX using nvm with node 10.15.3, I encountered an issue while attempting to follow the instructions for Testcafe-live at Testcafe-live. During the installation process outlined in the guide, If you have installed testcafe-live locally with ...

"Exploring the Power of ZF2 with Restful APIs and Image

I am currently in the process of developing a website utilizing Zend Framework 2 in combination with AngularJS. The backend consists of a restful webservice running on ZF2, while AngularJS is used on the client side to interact with this webservice. My ne ...

MooTools Request Unsuccessful

I'm encountering a problem with MooTools where every time I try to send a request, it fails. I'm having trouble figuring out the issue because when I attempt to retrieve the header info, the console just displays "Refused to get unsafe header &ap ...

Filtering out undefined elements from an array created by mapping over a nested array using map() and filter()

I'm currently in the process of creating multiple variables to be utilized later on, each one representing a specific array within a set of nested arrays (essentially a data array that will be used for various projects). As I attempt to select the pr ...

Utilizing JavaScript to manage a div's actions throughout various pages

I am currently working on an HTML project that involves having a collapsible text box on each page. However, I am struggling to figure out the best way to achieve the desired behavior. Essentially, some of the links will belong to a class that will set a v ...

Incorporating JavaScript Variables into MySQL Database with AJAX: A Step-By-Step

Looking to implement the solution provided in this query about adding records into a database using php/ajax/mysql: Best way to add records into DB using php/ajax/mysql? This is my current code: JavaScript function FromFlash(m1, m2, m3, m4){ var po ...

Injecting CSS styles into a webpage using a Chrome extension before the page has completely loaded to achieve instant customization

As a newcomer to creating Chrome (or other browser) extensions, I am working on developing one that applies custom CSS rules to specific page elements. Overall, it seems to be functioning as intended, but with some minor issues. One issue I have encounter ...