Skip to content

Instantly share code, notes, and snippets.

@puresamari
Created February 25, 2016 13:39
Show Gist options
  • Save puresamari/6b50c8871116271245ac to your computer and use it in GitHub Desktop.
Save puresamari/6b50c8871116271245ac to your computer and use it in GitHub Desktop.
My Gulpfile.js for angular 1.5.0 and Wordpress
'use strict';
var gulp = require('gulp'),
sass = require('gulp-sass'),
concat = require('gulp-concat-util'),
uglify = require('gulp-uglify'),
wrap = require("gulp-wrap");
var attrs = {
wp_theme_path: './wordpress/wp-content/themes/my_theme/',
dist_path: 'dist/'
},
debug = true;
gulp.task('sass', function () {
gulp
.src('src/scss/style.scss')
.pipe(sass({outputstyle:'compact'}))
.pipe(gulp.dest(debug ? attrs.wp_theme_path : attrs.dist_path));
});
gulp.task('img', function () {
gulp
.src('src/img/*')
.pipe(gulp.dest((debug ? attrs.wp_theme_path : attrs.dist_path) + 'img/'));
});
gulp.task('vendor', function(){
gulp
.src([
'node_modules/angular/angular.min.js',
'node_modules/angular-ui-router/release/angular-ui-router.min.js'
])
.pipe(concat('vendor.bundle.js'))
.pipe(gulp.dest((debug ? attrs.wp_theme_path : attrs.dist_path) +'vendor/'));
gulp
.src([
'node_modules/angular/angular.min.js.map',
'node_modules/angular-ui-router/angular-ui-router.min.js.map',
'node_modules/angular-sanitize/angular-sanitize.min.js.map'
])
.pipe(gulp.dest((debug ? attrs.wp_theme_path : attrs.dist_path) +'vendor/'));
});
gulp.task('js', function(){
gulp
.src([
'src/app/app.js',
'src/app/routes.js',
'src/app/controller/*.controller.js'
])
.pipe(uglify({
mangle: false,
output: {
beautify: true
}
}))
.pipe(concat.header('\n//<%= file.path %>\n\n'))
.pipe(concat('app.js'))
.pipe(wrap('(function(angular) {\n<%= contents %>\n})(window.angular);'))
.pipe(gulp.dest((debug ? attrs.wp_theme_path : attrs.dist_path )));
});
gulp.task('core', function(){
gulp
.src('src/php/**/*.php')
.pipe(gulp.dest(debug ? attrs.wp_theme_path : attrs.dist_path));
});
gulp.task('views', function(){
gulp
.src('src/views/**/*.htm')
.pipe(gulp.dest((debug ? attrs.wp_theme_path : attrs.dist_path) +'views/'));
});
gulp.task('templates', function(){
gulp
.src('src/templates/**/*.htm')
.pipe(gulp.dest((debug ? attrs.wp_theme_path : attrs.dist_path) +'templates/'));
});
gulp.task('watch', function () {
gulp.watch('src/scss/**/*.scss', ['sass']);
gulp.watch('src/app/**/*.js', ['js']);
gulp.watch('src/php/**/*.php', ['core']);
gulp.watch('src/views/**/*.htm', ['views']);
gulp.watch('src/templates/**/*.htm', ['templates']);
gulp.watch('src/img/*', ['img']);
});
gulp.task('default', ['vendor', 'watch']);
gulp.task('dist', function(){
debug = false;
gulp.start('vendor', 'sass', 'js', 'core', 'views', 'templates', 'img');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment