forked from zachfitz/Ionic-Material
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gulpfile.js
99 lines (82 loc) · 2.73 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
/* jshint esnext: true, asi: true */
const _ = require('lodash');
const gulp = require('gulp');
const minifycss = require('gulp-minify-css');
const rename = require('gulp-rename');
const concat = require('gulp-concat');
const uglify = require('gulp-uglify');
const livereload = require('gulp-livereload');
const sass = require('gulp-sass');
const sourcemaps = require('gulp-sourcemaps');
const gulpWebpack = require('gulp-webpack');
const webpack = require('webpack');
var connect = require('gulp-connect');
const distPath = './dist/';
var minify = false;
gulp.task('js', function () {
var src = [
'./src/js/lib/_motion.js',
'./src/js/lib/_ink.js'
];
var js = gulp.src(src)
.pipe(concat('ionic.material.js'))
.pipe(gulp.dest(distPath));
if (minify) {
js.pipe(uglify())
.pipe(rename('ionic.material.min.js'))
.pipe(gulp.dest(distPath))
}
return js;
});
gulp.task('serve', function(){
return connect.server();
});
gulp.task('webpack', function(){
var webpackConfig = require('./webpack.config.js');
var uglifyPlugin = new webpack.optimize.UglifyJsPlugin({
sourcemaps: false
});
var minifiedConfig = _.cloneDeep(webpackConfig);
if(!minifiedConfig.plugins || _.isEmpty(minifiedConfig.plugins)){
minifiedConfig.plugins = [];
}
minifiedConfig.plugins.push(uglifyPlugin);
minifiedConfig.output.filename = 'ionic.material.min.js';
return gulp.src('src/ionic-material.js')
.pipe(gulpWebpack(webpackConfig))
.pipe(gulp.dest(distPath))
.pipe(rename('ionic.material.js'))
.pipe(gulp.src('src/ionic-material.js')) // dunno if this is needed, just getting unminified src again
.pipe(gulpWebpack(minifiedConfig))
.pipe(gulp.dest(distPath))
.pipe(rename('ionic.material.min.js'));
});
gulp.task('styles', function () {
var src = './src/scss/index.scss';
var scss = gulp.src(src)
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(rename('ionic.material.css'));
if (minify) {
scss.pipe(gulp.dest(distPath)).pipe(rename({
suffix: '.min'
}))
.pipe(minifycss())
.pipe(rename('ionic.material.min.css'))
.pipe(sourcemaps.write()).pipe(gulp.dest(distPath));
} else {
scss.pipe(sourcemaps.write()).pipe(gulp.dest(distPath));
}
return scss;
});
gulp.task('watch', function () {
livereload.listen();
gulp.watch(['./*.js', '!./src/js/'], ['webpack']);
gulp.watch('./*.scss', ['styles']);
});
gulp.task('build', function () {
minify = true;
return gulp.start(['webpack', 'styles']);
})
gulp.task('default', ['webpack', 'styles', 'watch'], function () {
});