Gulp - Install Gulp and Laravel Elixir to compile your javascript files


 
Support my channels

If you love to use Javascript but want to compile it to minify file and split your files out to multi files so its coming more readable for you and orther in your code team, then i will recommend Gulp.js for this, i will here show you how you easy can start to using Gulp.js to your code project.

First you need to do its open your terminal and be sure you have installed node.js / npm, and then type the following.

npm install gulp-cli -g
npm install gulp -D
npm install laravel-elixir

When its installed you need to create the file gulpfile.js in your project folder and its tell gulp.js to use your settings you defined inside the file, you can now create the following lines before i explain about it.

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

elixir(function(mix) {
	mix.scripts([
		'app.js'
	],'public/js/app.min.js');
});

What we do here its tell we working with a script file mix.script where the first array will defined a list of files you want to compaile togetter in this case only main.js the secound its the place you want to place your compliled file public/js/app.min.js

Last start to create the file app.js this file need to be place in this folder resources/assets/js so this path are you need to create in your project folder before you create you app.js file.

Remeber to create your path public/js/ before we go to the next step to add a sample code to you app.js before you compile it. now you can go to app.js and write this line inside and save.

console.log('Hello world');

When you save this file and run gulp watch will gulp.js compile you code and place it to public/js/app.min.js try to open this file, and you can se the console.log line are inside.

You are now ready to play around as your self


Similar video courses