-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
67 lines (60 loc) · 1.99 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
const { src, dest, watch, series } = require('gulp');
const babel = require('gulp-babel');
const rename = require('gulp-rename');
var browserSync = require('browser-sync').create();
var sass = require('gulp-sass');
const cleanCSS = require('gulp-clean-css');
const zip = require('gulp-zip');
const terser = require('gulp-terser');
const autoprefixer = require('gulp-autoprefixer');
// Will compile es6 using babel and minify using terser.
function js() {
return src('./assets/src/js/*.js', {sourcemaps: true})
.pipe(babel({
presets: ['@babel/env']
}))
.pipe(terser())
.pipe(rename({ extname: '.min.js' }))
.pipe(dest('./assets/dist/js', {sourcemaps: true}));
}
// Will compile sass to css and minify.
function css() {
return src("./assets/src/sass/*.scss", {sourcemaps: true})
.pipe(sass())
.pipe(autoprefixer({
cascade: false,
}))
.pipe(cleanCSS({compatibility: 'ie8'}))
.pipe(rename({ extname: '.min.css' }))
.pipe(dest("./assets/dist/css", {sourcemaps: true}))
.pipe(browserSync.stream());
}
// Will create a zip file for plugin which will not contain unnecessary files.
function compress() {
return src([ '**/*', '!node_modules/**', '!./*.json', '!*.gitignore', '!gulpfile.js', '!.git/**' ])
.pipe(zip('debug-using-ngrok.zip'))
.pipe(dest('./'));
}
// Watches for changes
function watchTask() {
watch('./assets/src/sass/**/*.scss', css);
watch('./assets/src/js/**/*.js', js)
.on('change', browserSync.reload);
watch('./**/*.php')
.on('change', browserSync.reload);
};
// Opens up the browser
function browser(cb) {
browserSync.init({
proxy: "https://personal.local/"
});
cb();
}
exports.css = css;
exports.js = js;
exports.watch = watchTask;
exports.compress = compress;
exports.browser = browser;
exports.default = series(css, js, browser, watchTask);
// Will create a production build of the plugin.
exports.prod = series(css, js, compress);