-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
169 lines (154 loc) · 4.01 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
const autoprefixer = require('gulp-autoprefixer');
const concat = require('gulp-concat');
const cssnano = require('gulp-cssnano');
const gulp = require('gulp');
const gulpif = require('gulp-if');
const imagemin = require('gulp-imagemin');
const merge = require('merge-stream');
const path = require('path');
const replace = require('gulp-replace');
const sass = require('gulp-sass');
const svgMin = require('gulp-svgmin');
const svgSprite = require('gulp-svg-sprite');
const uglify = require('gulp-uglify');
const webpack = require('webpack');
const webpackStream = require('webpack-stream');
let API_HOST = 'http://localhost:8080';
let ENV = 'development';
if (process.env.ENV === 'production') {
API_HOST = '';
ENV = 'production';
}
gulp.task('fonts', () => {
return gulp.src([
'assets/fonts/**/*',
])
.pipe(gulp.dest('dist/fonts/'));
});
gulp.task('scripts', () => {
return gulp.src('assets/scripts/common.js')
.pipe(webpackStream({
devtool: process.env.ENV === 'production' ? false : 'source-map',
entry: './assets/scripts/common.js',
module: {
rules: [
{
test: /\.js$/,
exclude: path.resolve(__dirname, 'node_modules'),
loader: 'babel-loader',
options: {
presets: [
'es2015',
],
plugins: [
'transform-runtime',
],
},
},
],
},
output: {
filename: 'common.js',
},
resolve: {
modules: [
path.resolve('./node_modules/'),
path.resolve('./assets/scripts/'),
]
}
}, webpack))
.pipe(replace('{{API_HOST}}', API_HOST))
.pipe(replace('{{ENV}}', ENV))
.pipe(gulpif(process.env.ENV === 'production', uglify()))
.pipe(gulp.dest('dist/scripts'));
});
gulp.task('styles', () => {
const fontAssets = gulp.src([
'./assets/styles/fonts.scss',
]);
const staticAssets = gulp.src([
'./node_modules/sanitize.css/sanitize.css',
'./node_modules/leaflet/dist/leaflet.css',
'./node_modules/c3/c3.css',
]);
const sassAssets = gulp.src([
'./assets/styles/common.scss',
])
.pipe(sass().on('error', sass.logError));
fontAssets
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer())
.pipe(cssnano({
zindex: false,
discardUnused: {
fontFace: false,
},
}))
.pipe(gulp.dest('./dist/styles/'));
merge(staticAssets, sassAssets)
.pipe(autoprefixer({
browsers: [
'last 2 Chrome versions',
'last 2 Firefox versions',
'Explorer >= 10',
'last 1 Edge versions',
'last 3 iOS versions',
'last 2 Safari versions',
'last 2 ChromeAndroid versions',
'Android >= 4.1',
],
}))
.pipe(cssnano({
zindex: false,
}))
.pipe(concat('common.css'))
.pipe(gulp.dest('./dist/styles/'));
});
gulp.task('svg', () => {
return gulp.src('assets/images/**/*.svg')
.pipe(svgMin())
.pipe(svgSprite({
mode: {
css: false,
defs: {
dest: '',
sprite: './symbols.svg',
},
stack: false,
symbol: false,
view: false,
}
}))
.pipe(gulp.dest('dist/images'));
});
gulp.task('images', () => {
return gulp.src('assets/images/**/*')
.pipe(imagemin({
plugins: [
imagemin.jpegtran(),
imagemin.optipng(),
],
}))
.pipe(gulp.dest('dist/images'));
});
gulp.task('html', () => {
const version = require('./package.json').version;
return gulp.src('dev/**/*.html')
.pipe(replace('{{VERSION}}', `?v=${version}`))
.pipe(gulp.dest('./'));
});
gulp.task('watch', () => {
gulp.watch('./dev/**/*', ['html']);
gulp.watch('./assets/scripts/**/*', ['scripts']);
gulp.watch('./assets/styles/**/*', ['styles']);
gulp.watch('./assets/images/**/*.svg', ['svg']);
gulp.watch('./assets/images/**/*', ['images']);
});
gulp.task('default', [
'html',
'fonts',
'scripts',
'styles',
'svg',
'images',
]);