This repository has been archived by the owner on May 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
72 lines (64 loc) · 2.19 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
/*eslint-disable */
var gulp = require('gulp');
var gutil = require('gulp-util');
var webpackConfig = require('./webpack.config.js');
var webpack = require('webpack');
var del = require('del');
var rsync = require('gulp-rsync');
var path = require('path');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var CONFIG = {
dist: './dist'
};
gulp.task('clean-dist', function(cb) {
return del([CONFIG.dist], cb);
});
gulp.task('build', ['clean-dist'], function(cb) {
var myConfig = Object.create(webpackConfig);
myConfig.plugins = (myConfig.plugins||[]).concat([
new webpack.NoErrorsPlugin(),
new webpack.optimize.UglifyJsPlugin({
compressor: {
warnings: false
}
}),
new HtmlWebpackPlugin({
template: path.join(__dirname, 'src', 'index_prod.html')
}),
new webpack.DefinePlugin({
'process.env': {NODE_ENV: JSON.stringify('production')},
}),
new ExtractTextPlugin('[name]-[contenthash].css')
]);
myConfig.output.path = path.join(__dirname, CONFIG.dist);
myConfig.output.publicPath = 'http://projects.danielberndt.net/mapfix/';
myConfig.output.filename = "[name]-[hash].js";
myConfig.devtool = 'source-map';
styleLoader = myConfig.module.loaders.filter(function(loader){return loader.test.source === "\\.css$"; })[0];
var loaders = styleLoader.loader.split('!');
styleLoader.loader = ExtractTextPlugin.extract(loaders[0], loaders.slice(1).join('!'));
webpack(myConfig, function(err, stats) {
if (err) {
gutil.log(gutil.colors.red('Error (build): ' + err));
} else {
stats.compilation.warnings.forEach(function(warning) {gutil.log(gutil.colors.yellow(warning)); });
stats.compilation.errors.forEach(function(error) {gutil.log(gutil.colors.red(error)); });
}
if (err || stats.compilation.errors.length) {
cb(err||stats.compilation.errors[0]);
} else {
cb();
}
});
});
gulp.task('deploy', ['build'], function() {
return gulp.src([CONFIG.dist+'/**'])
.pipe(rsync({
root: CONFIG.dist,
username: 'www-data',
hostname: 'danielberndt.net',
destination: '~/projects/mapfix',
compress: true
}));
});