Compiling multiple CSS into ONE CSS with Laravel MIX

Viewed 6384

My current webpack.mix.js configuration is:

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

If I have another CSS, let's say 'plugin-1.css', how can I merge both so that I get an output of one app.css?

I tried ['resources/css/app.css', 'plugin-1.css'] but that's not an option.

3 Answers

The solution was to import all the required css into one main css file, then use that inside the mix chain:

app.css:

@import 'resources/css/plugin-1.css';
@import 'resources/css/plugin-2.css';

[the content...]

I usually use like this

mix.styles([
'resources/css/plugin-1.css',
'resources/css/plugin-2.css'
], 'public/assets/css/app.css');

You chain them

mix.js('resources/js/app.js', 'public/js')
.postCss('resources/css/app.css', 'public/css', [
    require('postcss-import'),
    require('tailwindcss'),
]).postCss('resources/css/plugin-1.css', 'public/css', [
    require('postcss-import'),
    require('tailwindcss'),
]).extract();
Related