Laravel Mix generate fonts into another directory

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company

Mastering Asset Management in Laravel Mix: Generating Structured Font Directories

As senior developers working within the Laravel ecosystem, we often deal with complex asset pipelines. Tools like Laravel Mix, which sits atop Webpack, are incredibly powerful for bundling CSS, JavaScript, and managing static assets. However, when dealing with custom asset directories—especially those containing vendor files like fonts—the default behavior of copying everything into a flat directory can become problematic.

This post dives deep into a common pain point: how to configure Laravel Mix to generate highly structured output directories, moving beyond the simple public/css and public/fonts structure to achieve cleaner organization, such as placing vendor assets under subdirectories.

The Challenge: Unstructured Asset Compilation

Let's examine the scenario you described. You have a package like font-awesome where the font files are nested within a specific directory (webfonts). When Laravel Mix compiles these assets, it defaults to dumping them into the root of the public folder (e.g., public/fonts), resulting in a flat structure:

php
public/
├───css/
│   └── frontend.css
└───fonts/
    ├── fa-regular-400.eot
    └── fa-regular-400.svg
    ... (all fonts dumped here)

Your goal is to achieve a vendor-style structure: public/fonts/vendor/font-awesome/.... The challenge lies in instructing Webpack/Mix not just what to compile, but where to place the resulting files relative to their source.

The Solution: Leveraging Mix Configuration for Custom Paths

Laravel Mix, being a wrapper around Webpack, relies heavily on its configuration file, webpack.mix.js, to define how assets are handled and moved during the compilation process. While direct file copying is often managed by underlying loaders, we can influence the output path using specific mix methods or by ensuring our source structure aligns with desired outputs.

For complex asset structures like this,