-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
148 lines (134 loc) · 4.53 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
var gulp = require('gulp')
var gutil = require("gulp-util")
var gulpSequence = require('gulp-sequence')
var fs = require("fs")
var path = require("path")
var clean = require('gulp-clean')
var colors = require('colors')
var plumber = require('gulp-plumber')
var zip = require('gulp-zip')
var imagemin = require("gulp-imagemin")
var pngquant = require('imagemin-pngquant')
var webpack = require("webpack")
var webpackDevServer = require("webpack-dev-server")
var webpackConfig = require("./webpack.config.js")
var appId = '10000066'
var buildPath = 'build_folder/10000066'
var buildTime = function() {
var timestamp = new Date().getTime()
fs.writeFileSync(path.join(__dirname, 'CERT'), '{"lastmodified":"' + timestamp + '"}');
console.log(colors.green.underline('Timestamp:' + timestamp))
}
gulp.task('clean', function () {
return gulp.src([buildPath,'build_zip/'+appId+'.zip',path.join(__dirname, '/static')],{read: false})
.pipe(clean({force: true}))
});
gulp.task('imagemin', function () {
return gulp.src('./static/*.{png,jpg,jpeg}')
.pipe(imagemin({
progressive: true,
svgoPlugins: [{removeViewBox: false}],
use: [pngquant()]
}))
.pipe(gulp.dest(buildPath + '/App/static'));
});
gulp.task('movehtml', function() {
return gulp.src('./*.html')
.pipe(gulp.dest(buildPath + '/App'));
});
gulp.task('movesingle', function() {
return gulp.src('./{CERT,package}')
.pipe(gulp.dest(buildPath));
});
gulp.task('movejs', function() {
return gulp.src('./static/{*.js,*.js.map}')
.pipe(gulp.dest(buildPath +'/App/static'));
});
gulp.task('zip', ['movesingle','movehtml','movejs','imagemin'], function() {
return gulp.src([buildPath +'/**'],{ base: __dirname + '/build_folder' })
.pipe(zip(appId + '.zip'))
.pipe(gulp.dest(__dirname+'/build_zip'));
});
// Production build
gulp.task("webpack:prod", ['clean'], function(callback) {
// modify some webpack config options
var myConfig = Object.create(webpackConfig);
myConfig.plugins = [
new webpack.ProvidePlugin({
"$": "zepto",
"Zepto": "zepto",
"window.Zepto": "zepto",
"_": "underscore",
"FastClick": "fastclick"
}),
new webpack.DefinePlugin({
'__DEV__': false,
'__TEST__': false,
'__PROD__': true,
}),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
}),
new webpack.optimize.OccurenceOrderPlugin()
]
// run webpack
webpack(myConfig, function(err, stats) {
if (err) throw new gutil.PluginError("webpack:prod", err);
gutil.log("[webpack:prod]", stats.toString({
colors: true
}));
callback();
});
});
gulp.task("webpack:test", ['clean'], function(callback) {
buildTime()
var myConfig = Object.create(webpackConfig);
myConfig.devtool = "inline-source-map";
myConfig.debug = true;
myConfig.plugins = [
new webpack.ProvidePlugin({
"$": "zepto",
"Zepto": "zepto",
"window.Zepto": "zepto",
"_": "underscore",
"FastClick": "fastclick"
}),
new webpack.DefinePlugin({
'__DEV__': false,
'__TEST__': true,
'__PROD__': false,
})
]
// run webpack
webpack(myConfig, function(err, stats) {
if (err) throw new gutil.PluginError("webpack:test", err);
// gutil.log("[webpack:test]", stats.toString({
// colors: true
// }));
callback();
});
});
gulp.task("webpack-dev-server",function(callback) {
buildTime()
// modify some webpack config options
var myConfig = Object.create(webpackConfig);
myConfig.devtool = "#source-map";
myConfig.debug = true;
myConfig.entry.app.unshift("webpack-dev-server/client?http://localhost:8080", "webpack/hot/dev-server");
// Start a webpack-dev-server
new webpackDevServer(webpack(myConfig), {
hot: true,
publicPath: myConfig.output.publicPath,
stats: {
colors: true
}
}).listen(8080, "localhost", function(err) {
if (err) throw new gutil.PluginError("webpack-dev-server", err);
gutil.log("[webpack-dev-server]", "http://localhost:8080/webpack-dev-server/index.html");
});
});
gulp.task("default", ["webpack-dev-server"]);
gulp.task("test", gulpSequence("webpack:test","zip"));
gulp.task("prod", gulpSequence("webpack:prod","zip"));