This repository has been archived by the owner on Oct 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 48
/
gulpfile.js
181 lines (164 loc) · 5 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
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
/**
* Copyright (c) Jupyter Development Team.
* Distributed under the terms of the Modified BSD License.
*/
var gulp = require('gulp'),
nodemon = require('gulp-nodemon'),
plumber = require('gulp-plumber'),
less = require('gulp-less'),
open = require('gulp-open'),
webpack = require('webpack'),
gutil = require('gulp-util'),
merge = require('merge-stream'),
expect = require('gulp-expect-file'),
config = require('./app/config'),
urljoin = require('url-join');
// default to 'production' if not set
var NODE_ENV = process.env.NODE_ENV && process.env.NODE_ENV.toLowerCase() === 'development' ?
'development' : 'production';
var baseUrl = config.get('BASE_URL') || '/';
var webpackStatsOptions = {
colors: gutil.colors.supportsColor,
hash: false,
timings: false,
chunks: false,
chunkModules: false, // set this & above to `true` to see which modules are complied in
modules: false,
children: true,
version: false,
cached: false,
cachedAssets: false,
reasons: false,
source: false,
errorDetails: false
};
// base configuration
var webpackConfig = {
bail: true,
entry: {
'dashboard': './client/js/dashboard.js'
},
module: {
loaders: [
{ test: /\.css$/, loader: 'style-loader!css-loader' },
{ test: /\.json$/, loader: 'json-loader' },
// jquery-ui loads some images
{ test: /\.(jpg|png|gif)$/, loader: "file" },
// required to load font-awesome
{ test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/, loader: "url?limit=10000&mimetype=application/font-woff" },
{ test: /\.woff(\?v=\d+\.\d+\.\d+)?$/, loader: "url?limit=10000&mimetype=application/font-woff" },
{ test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: "url?limit=10000&mimetype=application/octet-stream" },
{ test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: "file" },
{ test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: "url?limit=10000&mimetype=image/svg+xml" }
]
},
resolve: {
modulesDirectories: ['client/js', 'node_modules']
},
plugins: [],
output: {
filename: '[name].js',
path: './public/components',
publicPath: urljoin(baseUrl, '/components/')
}
};
// add addition config options depending on development vs production build
if (NODE_ENV === 'production') {
webpackConfig.plugins.push(
new webpack.optimize.UglifyJsPlugin({
minimize: true,
compress: {
warnings: false, // Suppress uglification warnings
}
})
);
webpackConfig.devtool = 'source-map';
} else {
webpackConfig.debug = true;
}
gulp.task('webpack:components', function(done) {
webpack(webpackConfig, function(err, stats) {
if (err) {
throw new gutil.PluginError('webpack', err);
}
gutil.log("[webpack]", stats.toString(webpackStatsOptions));
if (stats.hasErrors && stats.toJson().errors.length) {
done(new Error('during webpack compilation'));
} else {
done();
}
});
});
// copy source into `public/components`
gulp.task('copy:components', function() {
var tasks = [
{
files: [
'node_modules/requirejs/require.js',
],
dest: 'public/components'
},
{
files: [
'node_modules/font-awesome/fonts/*'
],
dest: 'public/components/fonts'
}
]
.map(function(list) {
return gulp.src(list.files)
.pipe(expect({ errorOnFailure: true }, list.files))
.pipe(gulp.dest(list.dest));
});
return merge.apply(this, tasks);
});
gulp.task('less', function () {
gulp.src('./client/less/style.less')
.pipe(plumber())
.pipe(less({
globalVars: {
BASE_URL: '"' + baseUrl + '"'
}
}))
.pipe(gulp.dest('./public/css'));
});
gulp.task('watch', function() {
gulp.watch('./client/less/*.less', ['less']);
gulp.watch('./client/js/*.js', ['webpack:components']);
});
var nodemonOptions = {
script: 'bin/jupyter-dashboards-server',
ext: 'js handlebars json',
stdout: false,
ignore: ['data/*']
};
gulp.task('develop', ['build'], function () {
nodemon(nodemonOptions).on('readable', function () {
this.stdout.pipe(process.stdout);
this.stderr.pipe(process.stderr);
});
});
gulp.task('debug-option', function() {
nodemonOptions.exec = 'node-inspector --no-preload & node --debug-brk';
});
gulp.task('open-debug-tab', function() {
gulp.src(__filename)
.pipe(open({uri: 'http://127.0.0.1:8080/?ws=127.0.0.1:8080&port=5858'}));
});
gulp.task('components', [
'webpack:components',
'copy:components'
]);
gulp.task('build', [
'less',
'components'
]);
gulp.task('default', [
'develop',
'watch'
]);
gulp.task('debug', [
'debug-option',
'default',
'open-debug-tab'
]);