question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to build multiple css files?

See original GitHub issue

This works:

mix
  .js('assets/js/admin.js', 'dist/js/')
  .js('assets/js/frontend.js', 'dist/js/')
;

However, this doesn’t:

mix
  .sass('assets/sass/admin.scss', 'dist/css/')
  .sass('assets/sass/frontend.scss', 'dist/css/')
;

It results in the following error:

Error: Laravel Mix: Limit your “mix.sass()” calls to one.

Is this a bug or an intended limitation?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:6
  • Comments:26 (4 by maintainers)

github_iconTop GitHub Comments

43reactions
JeffreyWaycommented, Jan 11, 2017

I just pushed support for this to master. Hasn’t been tagged yet, but will soon. So you can soon do:

mix.js('resources/assets/js/app.js', 'public/js')
   .sass('resources/assets/sass/app.scss', 'public/css')
   .sass('resources/assets/sass/other.scss', 'public/css')

And that will create public/css/app.css and public/css/other.css.

15reactions
pmuacommented, May 29, 2018
let mix = require('laravel-mix');

function mix_scss_files(folder) {
    let fs = require('fs');
    var relative_path = "resources/assets/sass" + folder;
    var paths = fs.readdirSync(relative_path);
    for (var i = 0; i < paths.length; i++) {
        if (paths[i].indexOf('.scss') > 0 && paths[i].charAt(0) != '_') {
            var file_path = relative_path + paths[i];
            console.log(file_path);
            mix.sass(file_path, 'public/css' + folder);
        }
    }
}
// sass root folder
mix_scss_files('/');
// sass subfolder resources/assets/sass/custom , trailing slash is necessary
mix_scss_files('/custom/');

mix.js('resources/assets/js/app.js', 'public/js');
Read more comments on GitHub >

github_iconTop Results From Across the Web

Can you apply multiple stylesheets to a single page? - CSS FAQ
Yes, you can apply more than one stylesheet to an HTML file. For each stylesheet you link to a page, you would just...
Read more >
Single huge .css file vs. multiple smaller specific .css files?
This is a hard one to answer. Both options have their pros and cons in my opinion. I personally don't love reading through...
Read more >
How to include one CSS file in another? - GeeksforGeeks
Is it possible to include one CSS file in another? Yes, It is possible to include one CSS file in another and it...
Read more >
How To Use Multiple CSS Files On A Large Web Project
The simplest way to combine external CSS files is to copy / paste all of the code you need into a single file....
Read more >
How could you generate multiple CSS files at once? #6612
My best guess is you want to have a separate CSS file for each "component" in your site? If that's the case just...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found