/
gulpfile.js
141 lines (126 loc) · 3.57 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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
const gulp = require('gulp'),
$ = require('gulp-load-plugins')(),
pkg = require('./package.json'),
banner = require('gulp-banner'),
cssnano = require('cssnano'),
cssMqpacker = require('css-mqpacker'),
faustaoErrou = require('gulp-faustao-errou'),
autoprefixer = require('autoprefixer'),
named = require('vinyl-named'),
connect = require('gulp-connect-php'),
browserSync = require('browser-sync'),
webpack = require('webpack-stream'),
windowsLocalServer = 'http://localhost:8082/estudos/',
isWindowsEnv = process.env.NODE_ENV && process.env.NODE_ENV === 'windows',
isProductionEnv = process.env.NODE_ENV && process.env.NODE_ENV === 'production';
const paths = {
icons: 'src/icons/**/*.svg',
js: 'src/scripts/**/*.js',
scss: 'src/styles/**/*.scss',
css: 'src/css/*.css',
php: './*.php',
webpack: 'src/scripts/*.js'
};
// Default comment
const comment = '/*\n' +
' * Theme Name: <%= pkg.name %>\n' +
' * Author: <%= pkg.author %>\n' +
' * Author URI: <%= pkg.homepage %>\n' +
' * Description: <%= pkg.description %>\n' +
' * Version: <%= pkg.version %>\n' +
'*/\n\n';
gulp.task('icons', () => {
const fontName = 'font-name';
return gulp.src(paths.icons)
.pipe($.iconfontCss({
fontName,
path: './src/icons/template.scss',
targetPath: '../styles/helpers/_icons.scss',
fontPath: './build',
}))
.pipe($.iconfont({
fontName,
normalize: true,
fontHeight: 1000,
centerHorizontally: true,
formats: ['ttf', 'eot', 'woff', 'svg', 'woff2'],
prependUnicode: false
}))
.pipe(gulp.dest('./src/fonts/'));
});
gulp.task('styles', () => {
return gulp.src(paths.scss)
.pipe($.plumber({ errorHandler: (err) => faustaoErrou.errou(err) }))
.pipe($.sass({
errLogToConsole: true,
outputStyle: 'compressed',
includePaths: ['src/styles', 'node_modules/tiny-slider/src/', 'node_modules/input-range-scss/', 'node_modules/glightbox/src/postcss/']
}).on('error', $.sass.logError))
.pipe($.postcss([
cssMqpacker({
sort: true
}),
cssnano({
autoprefixer: false,
reduceIdents: false
})
]))
.pipe($.postcss([
autoprefixer()
]))
.pipe(banner(comment, {
pkg: pkg
}))
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest('./'))
.pipe($.rename(file => file.basename = file.basename.replace('.min', '')))
.pipe(gulp.dest('./'))
.pipe(browserSync.stream());
});
gulp.task('scripts', () => {
return gulp.src(paths.webpack)
.pipe($.plumber({ errorHandler: (err) => faustaoErrou.errou(err) }))
.pipe(named())
.pipe(webpack({
mode: isProductionEnv ? 'production' : 'development',
output: {
filename: '[name].min.js'
},
resolve: {
modules: ['src/scripts', 'node_modules']
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader?cacheDirectory'
}
}
]
},
devtool: isProductionEnv ? '' : 'source-map',
optimization: {
minimize: !!isProductionEnv
}
}))
.pipe(gulp.dest('build/scripts'))
.pipe(browserSync.stream());
});
// Connect and start a local php server using gulp-connect-php
gulp.task('connect-sync', () => {
connect.server({}, () => {
browserSync({
proxy: isWindowsEnv ? windowsLocalServer : '127.0.0.1:8000'
});
});
gulp.watch(paths.php).on('change', () => browserSync.reload());
});
// Default task
gulp.task('default', ['styles', 'scripts', 'connect-sync', 'watch']);
// Watch task - Use to watch change in your files and execute other tasks
gulp.task('watch', ['styles', 'scripts'], () => {
gulp.watch([paths.js], ['scripts']);
gulp.watch([paths.scss], ['styles']);
});