How to use Laravel 5 with Gulp, Elixir and Bower? - gruntjs

I am completely new to all this, 'Bower' and 'Gulp' and Laravel 'Elixir'. I purchased a template that uses them (unfortunately) and now I need some help on how to go about implementing them. I have already installed NPM and Bower. All my packages have been downloaded into:
resources > assets > vendor
This is a screenshot:
Now my question is how do I include all those packages I downloaded in my view? From my understanding I can't run less files directly in the browser, it only runs once due to 'browser caching' or something like that, also the JS scripts are just too many to include in my page.
I want a way where I can work on my files and have them automatically compiled with the compiled files being referenced in my app.php file.
This is a link to the GulpJS file included in my template: http://pastebin.com/3PSN6NZY

You do not need to compile every time someone visits. The compiled sass/js should be run in dev and then the output files referenced.
If you have gulp installed on the project, you should see a gulp.js file in the root of your project. If not, visit here for instructions:
Gulp/Elixer installation and setup
In your gulp.js file:
var elixir = require('laravel-elixir');
elixir(function(mix) {
mix.less([
'app.less',
'normalize.less',
'some-other-less.less',
'and-another.less'
]);
mix.scripts(['app.js', 'some-other-js.js'], 'public/js/output-file.js');
});
While in development you can run gulp watch from the command line to listen for changes and run compile tasks when it hears a change. Then you simply reference the output files in the public directory as you normally would.
If you don't want to listen, you can just run the gulp command for a single once-off task run.
The docs are pretty straight forward and can be found here:
Gulp/Elixer docs

Related

Meteor + PhantomJS how to make it work

im trying to install PhantomJS in a MeteorApp.
I have done those step:
Add the npm package
meteor add meteorhacks:npm
Run meteor to let the npm package to pre-initialise
meteor
A file packages.json has been created at the root. Edit it to:
{
"phantomjs": "1.9.13"
}
A this point everything seem to work. But i try to test with this exemple that ive found here :
https://github.com/gadicc/meteor-phantomjs
But i dont understand where to put my phantomDriver.js
Why is phantomDriver.js is in assets/app/phantomDriver.js... but after, they say to create the file in ./private/phantomDriver.js...
Thank for clear explication :)
In development mode you create the file in /private/phantomDriver.js. When you build a meteor app it refactors everything into an application bundle which can be run.
After meteor builds your app it stores stuff from private into assets. For phantomjs to execute this file it needs to look in this directory. You don't have to create it. This is how meteor works internally.
If you look in your .meteor/local/build/programs/server directory the assets directory is there with anything you placed in private.
From the context of where your meteor code runs (the server directory above) the assets directory runs from this directory when your project is running.
Keep in mind when you deploy your app it loses its entire project structure and becomes something else. Gadi's phantomjs project is designed to work in production environments too.
TLDR; Don't worry about the assets directory, keep your file in /private/phantomDriver.js. Meteor should take care of the rest.

Is it possible to setup Gulp in a distributed fashion?

Here's what I want to do:
Create a node package that features the following:
gulpfile.js
All gulp plugins, tasks, configs.
Install this node package (referred to as "my-gulp" from here on) within an Angular app (referred to as "myApp" from here on) via package.json dependencies.
gulpfile.js is copied into app root.
All Gulp tasks can be run from app.
We currently have something similar setup with Grunt (although without the Gruntfile.js copy stuff). It works pretty well to have a common setup for each of our apps, but also several custom Bower components. Just have to bring it in as a dependency and it magically works.
The main issue I've run into so far is when I add my-gulp to myApp's dependencies, run the install, my-gulp comes in just fine, however the individual plugins (my-gulp dependencies) aren't seen. They're installed, but running something like gulp default or whatever shows them missing.
I've tried to setup Gulp dependencies (in my-gulp) under "dependencies" as opposed to "devDependencies", yet still not quite working.
Does anyone have any experience doing something like this?
Am I doing something blatantly stupid here?
Any help is awesome!
Thanks, everyone :)
The problem is the way npm handles nested dependencies. When you install your "my-gulp" package, the directory tree looks like this:
| myApp
|-- node_modules
|-- my-gulp
|-- node_modules
|-- gulp_dependency
As you can see, the dependencies of "my-gulp" are buried inside its own node_modules directory. myApp cannot access them.
You could use something like npm-flatten to move those to the top directory. Otherwise you'll be forced to add each dependency to myApp's package.json.
Edit:
As indicated in your gist, you can load the dependencies by path instead of package name. Instead of copying your gulpfile, simply require it from myApp, then load its dependencies with a relative path:
// myApp/gulpfile.js
require('my-gulp/gulpfile.js');
// my-gulp/gulpfile.js
var gulpDep = require('./node_modules/gulp-dependency');
Note: This won't work if you use npm dedupe.

How to tell Meteor to ignore `gulpfile.js`

In my meteor project I want to use gulp for tasks meteor doesn't support.
Anyway, the problem is that gulp uses a file called gulpfile.js which is loaded by meteor too and gives errors. So my question is, is there a way to tell meteor to ignore some files ?
UPDATE: One solution I can think of is to put gulpfile.js in the folder packages or public and run gulp as follows
$> gulp --gulpfile packages/gulpfile.js
UPDATE: Just noticed that meteor also seems to load node_modules files :(
Unfortunately, in the current release there's no way to tell Meteor to leave certain files alone, so you cannot have gulpfile.js in your main app folder.
You can, however, leave it in an ignored subfolder. Meteor ignores files and directories that ends with tilde ~, the /tests directory and all private files (those beginning with a dot .). So you can create a folder named for example gulp~ and use it for your gulp-related stuff.
The same holds for node_modules folder, you cannot have it in your application, and you shouldn't. If you want to use a node package in your Meteor application, you can do this with npm package.
Add it to your project with mrt add npm command.
Then create packages.json file with a list of all required packages, for example:
{
"something": "1.5.0",
"something-else": "0.9.11"
}
Afterwards, include your package with Meteor.require:
var something = Meteor.require('something');
If you want to use a node package in your gulp tasks, install it inside the ignored directory.

exclude directory from deployment (like tests)

i want to have a directory that is not deployed to the server, nor is it packaged to be sent to the clients.
I read the 'tests' dir behaves this way, but i don't want to store all my files that don't nee deployment in the tests dir. tests is just for tests...
I want to include my sass files (.scss) in my project, but only the compiled css needs to be deployed (I compile to client/style.css). All of the sass source files and compass configuration files don't need to be deployed anywhere.
How to do this?
I hope I don't need to stor everything in the tests dir...
Thanks!
Pieter
As stated in this other SO, directories whose name start with a dot (Unix hidden directories) aren't included by meteor. I use it for my less partials: client/css/.partials/_<partial_name>.less.
You could modify Meteor's app/lib/bundler.js, line 37 to include your extension:
var ignore_files = [
/~$/, /^\.#/, /^#.*#$/,
/^\.DS_Store$/, /^ehthumbs\.db$/, /^Icon.$/, /^Thumbs\.db$/,
/^\.meteor$/, /* avoids scanning N^2 files when bundling all packages */
/^\.git$/, /* often has too many files to watch */
/*.scss$/
];
or you could make package.js for your sass files, using stylus as an example.

Can't compile file using Compass

I have tried both ways to compile a project using compass (i.e. via the gui app, and the command line.)
I get this error in both instances. "Nothing to compile. If you're trying to start a new project, you have left off the directory argument.
Run "compass -h" to get help."
Where do you add the directory argument?
I suspect the way to get this working is just switch to your directory for your project and then run
compass init
This will then create you a "working" config.rb, and a directory called sass, and a directory stylesheets
and a couple of start scss files.
If you do not want them, or want to use different directories, you can of course now edit your freshly created and working config.rb, and change your directories (and then delete the old automatically created ones)
Anyway having done that(or not) you should then be able to run
compass watch
and all should be good , i.e. your scss files get compiled to css files
Or then run your gui tool
More information to be found in the compass documentation here

Resources