-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.babel.js
executable file
·222 lines (196 loc) · 5.04 KB
/
gulpfile.babel.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
// generated on 2015-08-23 using generator-gulp-webapp 1.0.3
import gulp from 'gulp';
import gulpLoadPlugins from 'gulp-load-plugins';
import browserSync from 'browser-sync';
import del from 'del';
// import { stream as wiredep } from 'wiredep';
import webpack from 'webpack'
import WebpackDevServer from 'webpack-dev-server'
import webpackConfig from './webpack.config.js'
const $ = gulpLoadPlugins();
const reload = browserSync.reload;
// webpack task
gulp.task("webpack-dev-server", function(callback) {
// Start a webpack-dev-server
var compiler = webpack(webpackConfig);
new WebpackDevServer(compiler, {
// server and middleware options
publicPath: "/docs/",
quiet: false,
noInfo: false,
stats: {
colors: true
}
}).listen(8080, "localhost", function(err) {
callback()
reload()
});
});
gulp.task('styles', () => {
return gulp.src('app/styles/*.scss')
.pipe($.plumber())
.pipe($.sourcemaps.init())
.pipe($.sass.sync({
outputStyle: 'expanded',
precision: 10,
includePaths: ['.']
}).on('error', $.sass.logError))
.pipe($.autoprefixer({
browsers: ['last 1 version']
}))
.pipe($.sourcemaps.write())
.pipe(gulp.dest('.tmp/styles'))
// .pipe(reload({
// stream: true
// }));
});
gulp.task('html', ['styles'], () => {
const assets = $.useref.assets({
searchPath: ['.tmp', 'app', '.']
});
return gulp.src('app/*.html')
.pipe(assets)
.pipe($.if('*.js', $.uglify()))
.pipe($.if('*.css', $.minifyCss({
compatibility: '*'
})))
.pipe(assets.restore())
.pipe($.useref())
.pipe($.if('*.html', $.minifyHtml({
conditionals: true,
loose: true
})))
.pipe(gulp.dest('docs'));
});
gulp.task('images', () => {
return gulp.src('app/images/**/*')
.pipe($.if($.if.isFile, $.cache($.imagemin({
progressive: true,
interlaced: true,
// don't remove IDs from SVGs, they are often used
// as hooks for embedding and styling
svgoPlugins: [{
cleanupIDs: false
}]
}))
.on('error', function(err) {
console.log(err);
this.end();
})))
.pipe(gulp.dest('docs/images'));
});
gulp.task('fonts', () => {
return gulp.src(require('main-bower-files')({
filter: '**/*.{eot,svg,ttf,woff,woff2}'
}).concat('app/fonts/**/*'))
.pipe(gulp.dest('.tmp/fonts'))
.pipe(gulp.dest('docs/fonts'));
});
gulp.task('extras', () => {
return gulp.src([
'app/*.*',
'app/CNAME',
'!app/*.html'
], {
dot: true
}).pipe(gulp.dest('docs'));
});
gulp.task('clean', del.bind(null, ['.tmp', 'docs']));
gulp.task('serve', ['styles', 'fonts'], () => {
browserSync({
notify: false,
port: 9000,
server: {
baseDir: ['.tmp', 'app'],
routes: {
'/bower_components': 'bower_components',
'/node_modules': 'node_modules',
}
}
});
gulp.watch([
'app/*.html',
'app/scripts/**/*.js',
// 'app/scripts/**/*.jsx',
'app/images/**/*',
'.tmp/fonts/**/*'
]).on('change', reload);
gulp.watch('app/styles/**/*.scss', ['styles']);
gulp.watch('app/fonts/**/*', ['fonts']);
// stop using bower
// gulp.watch('bower.json', ['wiredep', 'fonts']);
});
gulp.task('serve:docs', () => {
browserSync({
notify: false,
port: 9000,
server: {
baseDir: ['docs']
}
});
});
gulp.task('serve:test', () => {
browserSync({
notify: false,
port: 9000,
ui: false,
server: {
baseDir: 'test',
routes: {
'/bower_components': 'bower_components'
}
}
});
gulp.watch('test/spec/**/*.js').on('change', reload);
gulp.watch('test/spec/**/*.jsx').on('change', reload);
});
// Try using webpack for dependencies injection
// inject bower components
// gulp.task('wiredep', () => {
// gulp.src('app/styles/*.scss')
// .pipe(wiredep({
// ignorePath: /^(\.\.\/)+/
// }))
// .pipe(gulp.dest('app/styles'));
// gulp.src('app/*.html')
// .pipe(wiredep({
// exclude: ['bootstrap-sass'],
// ignorePath: /^(\.\.\/)*\.\./,
// overrides: {
// "outlayer": {
// "main": [
// "item.js",
// "outlayer.js"
// ]
// }
// }
// }))
// .pipe(gulp.dest('app'));
// });
gulp.task('build', ['html', 'images', 'fonts', 'extras', 'webpack:build'], () => {
return gulp.src('docs/**/*').pipe($.size({
title: 'build',
gzip: true
}));
});
gulp.task("webpack:build", function (callback) {
// modify some webpack config options
var myConfig = Object.create(webpackConfig);
myConfig.plugins = myConfig.plugins.concat(
new webpack.DefinePlugin({
"process.env": {
// This has effect on the react lib size
"NODE_ENV": JSON.stringify("production")
}
}),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin()
);
// run webpack
webpack(myConfig, function(err, stats) {
callback();
});
})
gulp.task('default', ['clean', 'webpack-dev-server'], () => {
gulp.start('serve');
});