jeudi 30 juin 2016

Laravel elixir copy not working on symbolic links

I'm creating a modular Laravel 5.2 app, which consists of a number of proprietary packages loaded on a Laravel installation using composer.

Each of the packages are responsible of managing its own assets (copy to public folder, compress, versioning, etc). To accomplish this, I have a gulpfile that uses elixir for each package, and then, they are loaded on the main gulpfile of the laravel installation.

This is the main gulpfile.js on the laravel installation:

var filesystem = require("fs");
var gulp = require('gulp');
var elixir = require('laravel-elixir');

gulp.task('default', function() {
    runPackagesGulpFiles();
});

function runPackagesGulpFiles() {
    var packagesPath = 'vendor/my-organization/';
    filesystem.readdirSync(packagesPath).forEach(function (file){
        try {
            var gulpFilePath = packagesPath + file + '/resources/assets/gulpfile.js';
            var fileStat = filesystem.statSync(gulpFilePath);
            require('./' + gulpFilePath);
        } catch (error) {
            if (error.message.indexOf('no such file or directory') < 0) {
                console.error(error.stack);
            }
        }
    });
}

All the main gulpfile.js does, is execute the packages gulpfiles if they exist using a require() function.

The following is an example of a package gulpfile:

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

elixir(function(mix) {
    mix.copy('vendor/my-organization/store-manager/resources/assets/js/', 'public/assets/js/elixir_components/store-manager/');
    mix.version([
        //Store structure versioning
        'assets/js/elixir_components/store-manager/stores/store.js',
        'assets/js/elixir_components/store-manager/stores/views.js',
        'assets/js/elixir_components/store-manager/stores/models.js',
        'assets/js/elixir_components/store-manager/stores/controllers.js',
        //Store resources versioning
        'assets/js/elixir_components/store-manager/resources/resources.js',
        'assets/js/elixir_components/store-manager/resources/views.js',
        'assets/js/elixir_components/store-manager/resources/models.js',
        'assets/js/elixir_components/store-manager/resources/controllers.js',
        //Store structure resources versioning
        'assets/js/elixir_components/store-manager/structures/structure.js',
        'assets/js/elixir_components/store-manager/structures/views.js',
        'assets/js/elixir_components/store-manager/structures/models.js',
        'assets/js/elixir_components/store-manager/structures/controllers.js',
    ]);
});

In a normal case scenario this works just fine. A normal case scenario being that the packages are loaded using composer.

However, for the development of the packages, I create a symbolic link in the vendor folder that points to the package folder in my local machine.

When I try to execute gulp in the development environment, I get a Cannot find module 'laravel-elixir' error:

[22:27:03] Using gulpfile ~/supermarket-cms/gulpfile.js
[22:27:03] Starting 'default'...
Error: Cannot find module 'laravel-elixir'
    at Function.Module._resolveFilename (module.js:339:15)
    at Function.Module._load (module.js:290:25)
    at Module.require (module.js:367:17)
    at require (internal/module.js:16:19)
    at Object.<anonymous> (/home/vagrant/Code/store-manager/resources/assets/gulpfile.js:1:76)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)
[22:27:03] Finished 'default' after 12 ms

Problem that I solved by installing laravel-elixir globally. But after I do so, the gulp task ends and my assets are not being copied.

[21:25:02] Using gulpfile ~/supermarket-cms/gulpfile.js
[21:25:02] Starting 'default'...
[21:25:02] Finished 'default' after 3.78 ms

No error whatsoever appears. Hope someone can help me. Thank you.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/29h6EQX
via IFTTT

Aucun commentaire:

Enregistrer un commentaire