forked from ibericode/mailchimp-top-bar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
74 lines (64 loc) · 2.37 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
'use strict';
const gulp = require('gulp');
const uglify = require('gulp-uglify');
const rename = require("gulp-rename");
const cssmin = require('gulp-cssmin');
const sourcemaps = require('gulp-sourcemaps');
const sass = require('gulp-sass');
const browserify = require('browserify');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
const wpPot = require('gulp-wp-pot');
const sort = require('gulp-sort');
const config = require('./package.json')
const insert = require('gulp-insert');
gulp.task('default', ['browserify', 'sass', 'minify-js', 'minify-css', 'languages' ]);
gulp.task('sass', function () {
var files = './assets/scss/[^_]*.scss';
return gulp.src(files)
// create .css file
.pipe(sass())
.pipe(rename({ extname: '.css' }))
.pipe(gulp.dest('./assets/css'))
});
gulp.task('browserify', function() {
return browserify({
entries: './assets/browserify/script.js'
}).on('error', console.log)
.bundle()
.pipe(source('script.js'))
.pipe(insert.wrap('(function () { var require = undefined; var module = undefined; var exports = undefined; var define = undefined;', '; })();'))
.pipe(buffer())
.pipe(gulp.dest('./assets/js'));
});
gulp.task('minify-js', ['browserify'], function() {
return gulp.src(['./assets/js/**/*.js','!./assets/js/**/*.min.js'])
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(buffer())
.pipe(uglify().on('error', console.log))
.pipe(rename({extname: '.min.js'}))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./assets/js'));
});
gulp.task('minify-css', ['sass'], function() {
return gulp.src(["./assets/css/**/*[^.min].css"])
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(cssmin({ sourceMap: true }))
.pipe(rename({extname: '.min.css'}))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest("./assets/css"));
});
gulp.task('languages', function () {
return gulp.src(['src/**/*.php', 'views/**/*.php'])
.pipe(sort())
.pipe(wpPot( {
domain: config.name,
destFile: config.name + '.pot'
} ))
.pipe(gulp.dest('languages'));
});
// Rerun the task when a file changes
gulp.task('watch', function() {
gulp.watch('./assets/browserify/**/*.js', ['browserify']);
gulp.watch('./assets/scss/**/*.scss', ['sass']);
});