5

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?

mistermat
  • 327
  • 4
  • 14

3 Answers3

1

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/');
});
Shiro
  • 7,344
  • 8
  • 46
  • 80
0

They are relative paths - so keep the relative relationship.

Just move the images over to the public/build/ directory as part of the gulp command, after the visioning.

Laurence
  • 58,936
  • 21
  • 171
  • 212
  • I guess that's what I meant by "manually" in point 1. Ie. I'm currently running mix.copy() to copy each folder over from my resources to public/build. Wondering if there's a better solution? – mistermat Jan 07 '15 at 05:50
  • unfortunately version task deletes folders other than under versioning... :/ – Karol F Jun 03 '15 at 20:04
  • @KarolFiturski That's why we copy it as part of the gulp command, in the gulpfile.js, instead of manually copying them. – Rafael Beckel Aug 26 '15 at 09:46
0

EDIT:

I just submitted a pull request to Elixir, so you can just do:

mix.version(
    ['css/style.css', 'css/vendor/style.css'], //files to be versioned
    ['fonts', 'css/vendor/icons'] //dependent files/dirs to be copied
);

OLD ANSWER:

Actually, if you use mix.copy(...) alone, you just can't use gulp watch and you'll need to recompile your entire stack in order to get this working.

You can achieve the same results with the solution below and don't need to recompile everything, because it'll just work when you change a versioned file:

var shell = require('gulp-shell');

gulp.task('cp', shell.task(['cp -R public/fonts public/build/',
                            'cp -R path/to/vendor/dir public/build/vendor/',
                            '... etc ...']));

elixir(function(mix) {

    ...

    //register a watcher to run 'cp' when you rebuild
    mix.task('cp','public/build/**/*.(js|css)');

}
Rafael Beckel
  • 2,199
  • 5
  • 25
  • 36
  • The mention pull request was never merged as far as I could see, so recommended is to use mix.copy if one would like to copy the files using Laravel Elixir (Mix) - see answers below. – Bert H Oct 23 '17 at 13:20