Compiling multiple CSS into ONE CSS with Laravel MIX

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company

Mastering CSS Merging in Laravel Mix: Combining Multiple Styles into One Output

As developers working within the Laravel ecosystem, we frequently deal with managing stylesheets, often involving frameworks like Tailwind CSS and custom utility files. When scaling up a project, the need to efficiently merge multiple source CSS files into a single production asset becomes critical. If you've run into issues merging files using mix.js() or PostCSS configurations, you’re not alone.

This post will dive into why your initial attempt might have failed and provide the robust, developer-approved method for combining numerous CSS files into one cohesive output using Laravel Mix.

Understanding the Limitation in Your Current Setup

You correctly identified that simply listing multiple files as input to mix.js() doesn't achieve a clean merge:

// Your attempt: This approach is often insufficient for simple concatenation
mix.js('resources/css/app.css', 'public/css') // Only processes this file directly
.postCss('resources/css/app.css', 'public/css', [ /* ... plugins ... */ ])

The issue stems from how Webpack (which Mix uses under the hood) handles asset bundling versus simple file copying. When you use .extract(), it extracts the contents of the specified input files. If you want to combine multiple sources before PostCSS runs, you need a mechanism that aggregates the content stream first.

The goal isn't just to copy files; it’s to instruct Webpack to treat these CSS files as modules that should be concatenated into a single stream before processing by PostCSS (like Tailwind).

The Solution: Leveraging CSS Imports for True Merging

The most idiomatic and powerful way to merge CSS files in a modern workflow, especially when using tools like PostCSS or preprocessors, is to rely on the native CSS @import functionality. This allows you to define a single entry point that recursively pulls in all necessary styles from other files.

If your goal is truly to consolidate multiple source files (e.g., app.css and plugin-1.css) into one final output, the best practice is to structure your imports so that they flow directly into the main file being processed by PostCSS.

Here is how you restructure your setup to achieve a single merged output:

Corrected Webpack Mix Configuration

Instead of relying on manually listing files for extraction, we will ensure that all required CSS logic resides within one primary entry point, using imports to handle the merging internally.

1. Organize Your Files: Ensure all styles you want merged are imported from your main entry file.

2. Update webpack.mix.js: Keep your core setup focused on processing one main file, letting internal imports handle the complexity.

// webpack.mix.js

const mix = require('mix');

// Define a single entry point for all CSS sources
mix.sass('resources/css/app.scss', 'public/css') // Use SCSS/Sass as the primary source
   .postCss('resources/css/app.scss', 'public/css', [
       require('postcss-import'), // This plugin handles merging @import directives
       require('tailwindcss'),
       // Add other necessary plugins here
   ])
   .extract();

Why This Works Better

By using a preprocessor like Sass (which is highly encouraged in the Laravel ecosystem, as seen in projects on laravelcompany.com), you leverage its native @import functionality. When PostCSS runs with postcss-import, it correctly resolves all nested imports from your primary SCSS file (app.scss) and merges the resulting CSS into the final output stream.

If you absolutely must combine two completely separate, non-importable files (e.g., legacy plugin files), you would need a custom Webpack loader or a pre-build script to concatenate the raw file contents before passing them to PostCSS. However, for standard component and utility merging, relying on the CSS import mechanism is vastly superior and cleaner.

Conclusion

Merging CSS in a build pipeline requires thinking about how your tools interact with the asset structure. Avoid trying to force Webpack/Mix into acting as a simple file concatenator when you can leverage the semantic power of preprocessors. By structuring your files using @import within a single entry point, and letting PostCSS handle the merging via postcss-import, you achieve clean, maintainable, and scalable CSS management. This approach aligns perfectly with the best practices promoted across the Laravel development landscape.