framework icon indicating copy to clipboard operation
framework copied to clipboard

Elixir not able to version multiple files?

Open beningreenjam opened this issue 11 years ago • 33 comments

I'm not sure if the website is lacking documentation on this, whether it's a genuine bug or if I'm just being derp. I'm also getting some other issues with it but I'll create separate issues tickets for them.

I'm trying to version two scripts and a css file, but no matter how I call the version method it only ever hashes the last file passed to it, or possibly it hashes them all but removes any files preceding the last one and my computer is too fast to for me to spot it.

Here's the contents of my package.json file:

{
  "dependencies": {
    "gulp": "^3.8.8",
    "laravel-elixir": "*"
  }
}

And here's the content of my gulpfile.js:

elixir(function (mix) {
    mix.less('bootstrap.less', 'public/assets/css/styles.min.css')
        .scripts([
            'dropdown.js',
            'collapse.js',
            'transition.js',
            'affix.js',
            'modal.js',
            'switch.js',
            'select2.js',
            'link.js',
            'custom.js'
        ], 'public/assets/js/global/main.js')
        .scriptsIn('resources/js/ie-hacks', 'public/assets/js/ie/ie-hacks.min.js')
        .version([
            'public/assets/css/styles.min.css',
            'public/assets/js/global/main.js',
            'public/assets/js/ie/ie-hacks.min.js'
        ]);
});

And my terminal outputs this a result:

/usr/bin/node /home/ben/source/www_icb/node_modules/gulp/bin/gulp.js --color --gulpfile /home/ben/source/www_icb/gulpfile.js [17:40:01] Using gulpfile ~/source/www_icb/gulpfile.js [17:40:01] Starting 'default'... [17:40:01] Starting 'less'... [17:40:02] Finished 'default' after 387 ms [17:40:03] gulp-notify: [Laravel Elixir]
[17:40:03] Finished 'less' after 1.85 s [17:40:03] Starting 'scripts'... [17:40:03] Finished 'scripts' after 146 ms [17:40:03] Starting 'version'... [17:40:03] Finished 'version' after 27 ms

Process finished with exit code 0

beningreenjam avatar Feb 09 '15 17:02 beningreenjam

"laravel-elixir": "*" is a bad idea. Set a constraint on the minor version at least. We have bc breaks that will screw your builds.

GrahamCampbell avatar Feb 09 '15 21:02 GrahamCampbell

I am seeing this exact same thing. Only my last .version is running.

natedavis avatar Feb 10 '15 00:02 natedavis

I installed Laravel 5 from fresh only last Thursday, via the composer laravel/installer script as documented on the site. which gave me those dependency versions in my packages.json.

I've now removed those dependencies and run the following: sudo npm install gulp --save and sudo npm install laravel-elixir --save, which has updated my packages.json file to the below:

{
  "dependencies": {
    "gulp": "~3.8.11",
    "laravel-elixir": "~0.10.7"
  }
} 

I'm still getting the same issues as before.

beningreenjam avatar Feb 10 '15 09:02 beningreenjam

I also have trouble versioning multiple scripts. But it's not always the last file that is kept.

mix.less('app.less')
    .scripts([
        'bootstrap/dist/js/bootstrap.min.js'
    ], 'public/js/vendor.js', 'resources/bower')
    .scripts(['app.js'], 'public/js/app.js')
    .copy('resources/bower/jquery/dist/jquery.min.js', 'public/js/jquery.min.js')
    .copy('resources/bower/bootstrap/dist/fonts/', 'public/fonts/bootstrap')
    .version(['css/app.css', 'js/vendor.js', 'js/app.js', 'js/jquery.min.js']);

Only app.css and app.js are always in the build dir/rev file, vendor.js an jquery sometimes. So might be a timing issue?

barryvdh avatar Feb 10 '15 11:02 barryvdh

Same, but when I use gulp watch, the file doesn't version, but does compile.


elixir(function(mix) {

    mix.less('app.less')

    mix.scriptsIn('public/js', 'public/js/compiled.js')

    mix.version([
        'css/app.css',
        'js/compiled.js'
    ])

});

js/compiled.js is never versioned when using gulp watch. I need to continuously run gulp to have scripts compile AND be versioned.

davidxd33 avatar Feb 10 '15 22:02 davidxd33

@natedavis are you trying to call .version multiple times? I did that too, but found out that you have to make a single call with an array if you want to version multiple files. I submitted a PR to the docs for this, but it hasn't been accepted yet.

memco avatar Feb 12 '15 02:02 memco

Also, to note that when using gulp watch, the files do not get versioned, but they do get compiled. (Defeats the purpose though)

Francismori7 avatar Feb 26 '15 14:02 Francismori7

This is happening to me too. I'm not calling version more than once either.

jaketoolson avatar Feb 27 '15 01:02 jaketoolson

Ping @JeffreyWay. :)

GrahamCampbell avatar Feb 28 '15 11:02 GrahamCampbell

Not getting this on latest version (and the gulp version --production is build during forge deployment).

https://github.com/orchestral/orchestraplatform.com/blob/master/gulpfile.js#L48 works fine.

crynobone avatar Feb 28 '15 12:02 crynobone

Thanks @crynobone.

GrahamCampbell avatar Feb 28 '15 14:02 GrahamCampbell

@crynobone in your example, you are only versioning 1 JS file and 1 CSS file vs many as is given in this example.

The one particular file not being versioned has over 12 .js files (vendors). When I whittle this down to about 6, all my files version correctly.

mix.scripts([
            "vendor/jquery.1.11.2.js",
            "vendor/bootstrap.3.3.2.js",
            "vendor/enquire.min.js",
            "vendor/media.match.min.js",
            "vendor/placeholdr.min.js",
            "vendor/bootstrap-editable.min.js",
            "vendor/bootstrap-notify.js",
            "vendor/select2.full.js",
            "vendor/bootstrap-tabdrop/js/bootstrap-tabdrop.js"
        ], "public/assets/js/vendor.js")

.version([
            'public/assets/css/vendor.css',
            'public/assets/css/theme.css',
            'public/assets/css/app.css',
            'public/assets/js/vendor.js',
            'public/assets/js/theme.js',
            'public/assets/js/app.js'
        ]); 

@GrahamCampbell , upon removing everything but vendor.js from version, no builds are versioned (expecting 1 - vendor.js). But the compressed and merged vendor.js file is created and appears in the specified folder. Versioning still fails.

As @barryvdh said, perhaps there is a time issue because I have so many scripts being merged because in removing jquery and bootstrap.js, vendor.js compiles just fine.

jaketoolson avatar Mar 08 '15 22:03 jaketoolson

In your example, you are only versioning 1 JS file and 1 CSS file vs many as is given in this example.

In the earlier comment, the argument was only one build file was available.

The one particular file not being versioned has over 12 .js files (vendors). When I whittle this down to about 6, all my files version correctly.

Have you tried separating the process such as my example.

mix.scripts(...);

// separate mix.
mix.version(..);

This way you can call gulp version directly, if you need to.

crynobone avatar Mar 08 '15 23:03 crynobone

Hi all,

I have the same problem. The version() method is not working when I try to version a file that was created with more than 2 files (with 2 files it works ok).

Here is the example:

// Compile app.js
mix.scripts([
    'vendor/jquery.js',
    'vendor/bootstrap.js',
    'controllers/general-controller.js'
], 'public/js/app.js', 'public/js');

// Version scripts
mix.version(["js/app.js"]);

The rev-manifest.json file doesn´t include the file, and the build folder is empty. If I remove one file on the list of compiled scripts works as expected.

I tried running "gulp version" and it worked ok. So, I think that is an issue when you try to do all the tasks at the same time.

sergiogregorutti avatar Mar 13 '15 12:03 sergiogregorutti

Yeah - this is odd. I just reproduced your exact structure, and it merged and versioned perfectly.

JeffreyWay avatar Mar 13 '15 15:03 JeffreyWay

@JeffreyWay @SergioGregorutti @jaketoolson @crynobone - what development environments are you using?

I'm wondering if people who are having the bug are using Windows environments, while people using Mac/Linux are passing ok?

Windows users (even on Homestead using Ubuntu), can have a 'race condition' with gulp doing files and the sync between the VM and drive.

I know I had this issue myself (as a Windows + Homestead user). I am trying to remember how I fixed it - but before I spend more time on it - lets confirm if that is the problem?

laurencei avatar Mar 13 '15 15:03 laurencei

@JeffreyWay - before I used Exilir - I used to do automatic versioning in gulp. But I had issues sometimes where versioned files would randomly not be created etc (very similar to the above).

After much debugging - the issue was a race condition, where gulp would want to start versioning files, even though other processes hadnt finished writing the output css files first.

I ended up using run-sequence (https://www.npmjs.com/package/run-sequence) - to ensure that everything else ran first, and the once everything was 100% complete - it would then run the versioning as a final command.

This fixed the issue for me. Although I dont have the issues with Exilir described above - it sounds similar to what used to affect me.

Maybe add it to a dev branch and see if it fixes the problem?

laurencei avatar Mar 13 '15 16:03 laurencei

@TheShiftExchange I have the issue on Mac and Linux.

On package.json I have:

"laravel-elixir": "*"

Maybe I need to use a specific version? Which one is the last one?

sergiogregorutti avatar Mar 13 '15 19:03 sergiogregorutti

I can't get versioning to work either with sass, it works fine for my js, just not my sass. My sass compiles fine.

elixir(function(mix) {
    mix.sass('app.scss')
    .version(["css/all.css"]);
});

tshafer avatar Mar 13 '15 23:03 tshafer

I´m trying with:

"laravel-elixir": "0.13.1"

But is still not working. Which are the steps to update the package version? Maybe Im doing something wrong. I tried executing "npm install" but the issue still persist.

Btw, Im just trying to help to improve Elixir. It seems like there're anothers guys like me having this problem.

Thanks!

sergiogregorutti avatar Mar 14 '15 00:03 sergiogregorutti