This repository has been archived by the owner on Jun 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
gulpfile.js
136 lines (120 loc) · 4.15 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
'use strict';
var gulp = require('gulp');
// var gutil = require('gulp-util');
var derequire = require('gulp-derequire');
var livereload = require('gulp-livereload');
var plumber = require('gulp-plumber');
var sourcemaps = require('gulp-sourcemaps');
var electron = require('electron-connect').server.create();
var paths = {
styles: 'src/css/**/*.css',
scripts: 'src/js/**/*.js'
};
// Build stylesheets
gulp.task('css', function () {
var postcss = require('gulp-postcss');
var autoprefixer = require('autoprefixer');
var cssimport = require('postcss-import');
var nested = require('postcss-nested');
var customProperties = require('postcss-custom-properties');
var colorHexAlpha = require('postcss-color-hex-alpha');
var csswring = require('csswring');
var reporter = require('postcss-reporter');
var plugins = [
cssimport,
nested,
customProperties(),
colorHexAlpha(),
autoprefixer({ browsers: ['last 2 versions', 'IE >= 11'] }),
// preserveHacks is true because NOT preserving them doesn't mean
// delete the hack, it means turn it into real CSS. Which is not
// what we want!
csswring({ removeAllComments: true, preserveHacks: true }),
reporter()
];
return gulp.src('./src/css/shaderNinja.css')
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(postcss(plugins))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('./build'))
.pipe(livereload());
});
// Build Javascripts
gulp.task('js', function () {
var browserify = require('browserify');
var shim = require('browserify-shim');
var babelify = require('babelify');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var bundle = browserify({
entries: 'src/js/ShaderNinja.js',
standalone: 'ShaderNinja',
debug: true,
transform: [
babelify.configure({ optional: ['runtime'] }),
shim
]
});
return bundle.bundle()
.pipe(plumber())
.pipe(source('shaderNinja.js'))
.pipe(derequire())
.pipe(buffer())
// .pipe(sourcemaps.init({ loadMaps: true }))
// Add transformation tasks to the pipeline here.
// .on('error', gutil.log)
// .pipe(sourcemaps.write('.'))
.pipe(gulp.dest('./build'))
.pipe(uglify())
.pipe(rename({ extname: '.min.js' }))
.pipe(gulp.dest('./build'));
});
// Build ThreeCanvas
gulp.task('ThreeCanvas', function () {
var browserify = require('browserify');
var shim = require('browserify-shim');
var babelify = require('babelify');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var bundle = browserify({
entries: 'src/js/ThreeCanvas.js',
standalone: 'ThreeCanvas',
debug: true,
transform: [
babelify.configure({ optional: ['runtime'] }),
shim
]
});
return bundle.bundle()
.pipe(plumber())
.pipe(source('ThreeCanvas.js'))
.pipe(derequire())
.pipe(buffer())
.pipe(gulp.dest('./build'))
.pipe(uglify())
.pipe(rename({ extname: '.min.js' }))
.pipe(gulp.dest('./build'));
});
// Rerun the task when a file changes
gulp.task('watch', function () {
livereload.listen();
gulp.watch(paths.styles, ['css']);
gulp.watch(paths.scripts, ['js']);
});
gulp.task('run', function () {
// Start browser process
electron.start();
// Reload browser process
gulp.watch(['build/shaderNinja.css', 'build/shaderNinja.js','build/ThreeCanvas.js','src/index.html'], electron.reload);
gulp.watch(['src/main.js'], electron.restart);
});
// Build files, do not watch
gulp.task('build', ['css', 'js', 'ThreeCanvas']);
gulp.task('electron', ['css', 'js', 'ThreeCanvas','watch', 'run']);
// The default task (called when you run `gulp` from cli)
gulp.task('default', ['css', 'js','ThreeCanvas', 'watch']);