-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js.example
executable file
·115 lines (102 loc) · 3.39 KB
/
gulpfile.js.example
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
const gulp = require('gulp');
const sass = require('gulp-sass')(require('node-sass'));
const uglify = require('gulp-uglify');
const include = require('gulp-include');
const cleanCSS = require('gulp-clean-css');
const sourcemaps = require('gulp-sourcemaps');
const browserSync = require("browser-sync").create();
const postcss = require('gulp-postcss');
const autoprefixer = require('autoprefixer');
const themePath = 'theme/';
const distPath = 'public/theme/';
// browser sync proxy url: e.g. a vhost-based url,
// see also: https://www.browsersync.io/docs/options#option-proxy
const bsProxy = 'nutshell.localhost';
const paths = {
src: {
styles: themePath + 'scss/default.scss',
scripts: themePath + 'js/**/*.js',
images: themePath + 'img/**/*',
fonts: themePath + 'fonts/**/*'
},
dist: {
styles: distPath + 'css',
scripts: distPath + 'js',
images: distPath + 'img',
fonts: distPath + 'fonts'
},
watch: {
styles: themePath + 'scss/**/*.scss',
scripts: themePath + 'js/**/*.js',
images: themePath + 'img/**/*',
templates: 'templates/**/*'
},
};
// reading your sass files, add autoprefixer options, create sourcemaps, generate css file, inject css via browser-sync
const styles = function() {
return gulp.src(paths.src.styles)
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(postcss([
autoprefixer({cascade: false})
]))
.pipe(sourcemaps.write('../maps'))
.pipe(gulp.dest(paths.dist.styles))
.pipe(browserSync.stream({ match: '**/*.css' }));
};
exports.styles = styles;
// nearly the same that ['styles'] does, but minify css via cleanCSS
const minifyCss = function() {
return gulp.src(paths.src.styles)
.pipe(sass())
.pipe(postcss([
autoprefixer({cascade: false})
]))
.pipe(cleanCSS())
.pipe(gulp.dest(paths.dist.styles));
};
exports.minify_css = minifyCss;
// read, combine and uglyify js
const scripts = function() {
return gulp.src(paths.src.scripts)
.pipe(include())
.pipe(uglify())
.pipe(gulp.dest(paths.dist.scripts));
};
exports.scripts = scripts;
// read and optimize images
const images = function () {
return gulp.src(paths.src.images)
.pipe(gulp.dest(paths.dist.images));
};
exports.images = images;
// copy static files from src to dist
const copy = function() {
return gulp.src(paths.src.fonts)
.pipe(gulp.dest(paths.dist.fonts));
};
exports.copy = copy;
const reload = function() {
browserSync.reload();
};
const watch = function(done) {
gulp.watch(paths.watch.styles, gulp.series([styles]));
gulp.watch(paths.watch.templates).on('change', reload);
gulp.watch(paths.watch.scripts, gulp.series([scripts])).on('change', reload);
done();
};
const serve = function(done) {
browserSync.init({
proxy: bsProxy,
/* activate for local https
https: { key: "/usr/local/etc/httpd/certs/localhost-key.pem", cert: "/usr/local/etc/httpd/certs/localhost.pem" },
*/
open: false,
injectNotification: 'overlay'
}, () => {
done();
});
};
exports.serve = serve;
exports.default = gulp.parallel([serve, watch]);
exports.deploy = gulp.series([minifyCss, scripts, images, copy]);