Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asset management - maintaining reference to relative assets after concatenation and versioning

I know that L5 and Elixir are still under development, but I'm excited to start thinking about ways to reorganize my code. I think my question has more to do with asset management, in the context of L5 and Elixir.

Want to clarify how concatenation and versioning should be handled (in my case I'm using Elixir's styles() and version()). The issue I'm having is that the new file after concat/version will be located in a new folder, breaking any references to assets from the original css or js files.

For example, an original CSS file that has background-image: url('../img.png') will no longer work. I've tried a couple of things, but both are not ideal especially in the case of vendor plugins:

  1. Move required assets over one-by-one (using mix.copy() for each folder of assets), to the new build path (ie. the build path used by Elixir's versioning).
  2. Manually edit the paths in each asset file to refer to an absolute path

Although both of these options will make things work, I feel as though I may be missing something. It also becomes quite impractical when working with javascript plugins (ex. ones that come with their own images, fonts, stylesheets, etc).

Is there a more practical way of managing relative paths when concatenating and versioning?

like image 884
mistermat Avatar asked Nov 09 '22 21:11

mistermat


1 Answers

Here is the solution for Laravel Elixir after you build for versioning. For copy command you need reference it as full path.

var elixir = require('laravel-elixir');

/*
 |--------------------------------------------------------------------------
 | Elixir Asset Management
 |--------------------------------------------------------------------------
 |
 | Elixir provides a clean, fluent API for defining some basic Gulp tasks
 | for your Laravel application. By default, we are compiling the Less
 | file for our application, as well as publishing vendor resources.
 |
 */

elixir(function(mix) {
    mix.version('themes/default/assets/css/styles.css')
        .copy('public/themes/default/assets/img/', 'public/build/themes/default/assets/img/');
});
like image 96
Shiro Avatar answered Nov 15 '22 12:11

Shiro