To achieve the desired setup where you have two different CSS files with distinct configurations using Vite and Tailwind CSS, you can configure Vite to handle multiple entry points and use different PostCSS configurations for each. Here's a step-by-step guide on how you can set this up:
-
Create Separate PostCSS Configurations:
First, create two separate PostCSS configuration files. One for your main application and another for the PDF generation.
-
postcss.config.js(for the main application):module.exports = { plugins: { tailwindcss: {}, autoprefixer: {}, }, }; -
postcss.pdf.config.js(for PDF generation):module.exports = { plugins: { tailwindcss: {}, autoprefixer: { overrideBrowserslist: ['Chrome 13'], }, }, };
-
-
Configure Vite to Use Multiple Entry Points:
In your
vite.config.js, you can specify multiple entry points for your CSS files. You will also need to specify which PostCSS configuration to use for each entry point.import { defineConfig } from 'vite'; import laravel from 'laravel-vite-plugin'; export default defineConfig({ plugins: [ laravel({ input: [ 'resources/css/app.css', // Main application CSS 'resources/css/pdf.css', // PDF generation CSS ], refresh: true, }), ], css: { postcss: (file) => { if (file.includes('pdf.css')) { return require('./postcss.pdf.config.js'); } return require('./postcss.config.js'); }, }, }); -
Create Separate CSS Files:
Ensure you have two separate CSS files in your resources directory:
-
resources/css/app.cssfor your main application styles. -
resources/css/pdf.cssfor your PDF styles.
You can import Tailwind and any other necessary styles in these files.
-
-
Build and Test:
Run your Vite build process to generate the CSS files. You should now have two separate CSS files, each processed with its respective PostCSS configuration.
npm run build
By following these steps, you should be able to generate two different CSS files with Vite, each tailored to its specific use case with the appropriate PostCSS configuration. This setup allows you to maintain modern CSS for your web application while ensuring compatibility with older browsers for PDF generation.