Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Hectix's avatar

Laravel mix duplicated code on output.

Hi guys,

When I use the same file for output as one of the input file, output has duplicated content.

mix.styles([
        'node_modules/bs-stepper/dist/css/bs-stepper.min.css',
        'node_modules/select2/dist/css/select2.min.css',
        'public/css/study-form.css' // different file
    ], 'public/css/study-form_test.css'); // different file

or

mix.styles([
        'node_modules/bs-stepper/dist/css/bs-stepper.min.css',
        'node_modules/select2/dist/css/select2.min.css',
        'public/css/study-form.css' // same  file 
    ], 'public/css/study-form.css'); // same file

Why? How should I handle this? I mean, I dont want one redundant file there. Thanks

0 likes
4 replies
Cronix's avatar

Why wouldn't you output them all to a new single file? If you think about what you're asking, the behavior is logical. Take content of file A and append to end of file A. Of course you'd get duplicate?

That's basically what it's doing - cutting contents of one file and pasting in another. Don't have them (source and destination) be the same file.

mix.styles([
        'node_modules/bs-stepper/dist/css/bs-stepper.min.css',
        'node_modules/select2/dist/css/select2.min.css',
        'public/css/study-form.css'
    ], 'public/css/some-unique-filename.css'); // new file containing all
Hectix's avatar

@CRONIX - That's what I wanted to avoid. If I create a new unique file, the previous file that I've tried to concat will become redundant in a project.

Cronix's avatar

Well, I don't use any minified source files. I use the mix().version() command to do the minification on the final output file. The only file I serve (in the example I posted) would be the single file from the output.

Maybe you want to just use combine() instead of styles().

Hectix's avatar

@CRONIX - You probably misunderstood my case.

I have one sass file, and I want it to compile, and that compiled file combine with node modules styles. After that, that previously compiled sass file is useless in project.

Please or to participate in this conversation.