forked from onefinestay/react-daterange-picker
-
Notifications
You must be signed in to change notification settings - Fork 5
/
gulpfile.babel.js
178 lines (154 loc) · 4.6 KB
/
gulpfile.babel.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
Object.assign = require('object.assign');
import fs from 'fs';
import path from 'path';
import gulp from 'gulp';
import gulpLoadPlugins from 'gulp-load-plugins';
import React from 'react';
import ReactDOMServer from 'react-dom/server';
import webpack from 'webpack';
import { Server as KarmaServer } from 'karma';
import clean from 'del';
import runSequence from 'run-sequence';
import ExampleBase from './example/base.jsx';
const plugins = gulpLoadPlugins();
const PRODUCTION = (process.env.NODE_ENV === 'production');
let gulpPlugins = [
// Fix for moment including all locales
// Ref: http://stackoverflow.com/a/25426019
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
];
if (PRODUCTION) {
gulpPlugins.push(new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify("production"),
},
}));
gulpPlugins.push(new webpack.optimize.DedupePlugin());
gulpPlugins.push(new webpack.optimize.UglifyJsPlugin({
compress: true,
mangle: true,
sourceMap: true,
}));
}
const webpackConfig = {
cache: true,
debug: !PRODUCTION,
devtool: PRODUCTION ? 'source-map' : 'eval-source-map',
context: __dirname,
output: {
path: path.resolve('./example/build/'),
filename: 'index.js',
},
module: {
loaders: [
{
test: /\.jsx|.js$/,
exclude: /node_modules\//,
loader: 'babel',
},
],
postLoaders: [
{
loader: "transform/cacheable?brfs",
},
],
},
resolve: {
extensions: ['', '.js', '.jsx'],
},
plugins: gulpPlugins,
};
gulp.task('lint', function() {
return gulp.src('**/*.js?(x)')
.pipe(plugins.eslint({ ignorePath: '.eslintignore' }))
.pipe(plugins.eslint.format())
.pipe(plugins.eslint.failAfterError());
});
gulp.task('test-unit', ['lint'], function (done) {
new KarmaServer({
configFile: __dirname + '/karma.conf.js',
}, done).start();
});
gulp.task('test-coverage', ['lint'], function (done) {
new KarmaServer({
configFile: __dirname + '/karma.conf.js',
reporters: ['mocha', 'coverage', 'threshold'],
singleRun: true,
webpack: {
module: {
preLoaders: [
{
test: /\.spec.js$/,
include: path.resolve('src/'),
loader: 'babel',
},
],
loaders: [
{test: /\.(js|jsx)$/, exclude: /node_modules/, loader: require.resolve('babel-loader')},
],
},
resolve: {
extensions: ['', '.js', '.jsx'],
},
},
}, done).start();
});
gulp.task('clean-dist', function() {
return clean('dist');
});
gulp.task('build-dist-js', function() {
// build javascript files
return gulp.src(['src/**/*.{js,jsx}', '!src/**/tests/**', '!src/tests.webpack.js'])
.pipe(plugins.babel())
.pipe(plugins.extReplace('.js'))
.pipe(gulp.dest('dist'));
});
gulp.task('build-dist-scss', function() {
gulp.src('./src/css/**/*.scss')
.pipe(plugins.sass())
.pipe(plugins.autoprefixer())
.pipe(gulp.dest('./dist/css'));
});
gulp.task('build-dist', function(callback) {
runSequence('clean-dist', ['build-dist-js', 'build-dist-scss'], callback);
});
gulp.task('build-example-js', function() {
var compiler = plugins.webpack(webpackConfig, webpack);
return gulp.src('./example/js/index.js')
.pipe(compiler)
.pipe(gulp.dest('./example/build'));
});
gulp.task('watch-example-js', function() {
var compiler = plugins.webpack(Object.assign({}, {watch: true}, webpackConfig), webpack);
return gulp.src('./example/js/index.js')
.pipe(compiler)
.pipe(gulp.dest('./example/build'));
});
gulp.task('build-example', function() {
var markup = '<!document html>' + ReactDOMServer.renderToString(<ExampleBase />);
// write file
fs.writeFileSync('./example/index.html', markup);
});
gulp.task('build-example-scss', function() {
gulp.src(['./example/css/**/*.scss', './src/css/**/*.scss'])
.pipe(plugins.sass())
.pipe(plugins.autoprefixer())
.pipe(gulp.dest('./example/css'));
});
gulp.task('watch-example-scss', ['build-example-scss'], function() {
plugins.watch(['./example/**/*.scss', './src/css/**/*.scss'], function(files, cb) {
gulp.start('build-example-scss', cb);
});
});
gulp.task('example-server', function() {
plugins.connect.server({
root: 'example',
port: '9989',
});
});
gulp.task('build', ['build-dist', 'build-example', 'build-example-js', 'build-example-scss']);
gulp.task('develop', ['test-unit', 'build-example', 'watch-example-js', 'watch-example-scss', 'example-server']);
gulp.task('deploy-example', ['build'], function() {
return gulp.src('./example/**/*')
.pipe(plugins.ghPages());
});