-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
97 lines (81 loc) · 2.17 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
const gulp = require('gulp');
const rename = require('gulp-rename');
const babel = require('gulp-babel');
import webpack from 'webpack';
import WebpackDevServer from 'webpack-dev-server';
const path = require('path');
import createShell from './utils/createShell';
const paths = {
models: path.join('src', 'SDK')
};
const config = {
createModels: {
babel: {
"plugins": [
"babel-plugin-syntax-flow",
'babel-plugin-syntax-decorators',
'babel-plugin-syntax-class-properties',
"babel-plugin-immutable-record"
]
}
}
};
/**
* Inject webpack plugin with app configuration.
* @param {object} config Webpack configuration.
*/
const injectConfig = (config) => {
if (!config.plugins) config.plugins = [];
config.plugins.push(
new webpack.DefinePlugin({
'window.config': {
apiUrl: JSON.stringify('apiUrl'),
}
})
);
}
/**
* Map models schema to immutable records.
*/
gulp.task('create-models', () => {
process.env.BABEL_ENV = 'process';
return gulp.src('src/Types/**/*.js')
.pipe(babel(config.createModels.babel))
.pipe(gulp.dest(paths.models));
delete process.env.BABEL_ENV;
});
/**
* Create application shell structure.
*/
gulp.task('create-shell', function () {
createShell();
});
/**
* Run development server.
*/
gulp.task('development', () => {
process.env.BABEL_ENV = 'development';
const webpackConfig = require('./webpack.dev.config');
injectConfig(webpackConfig);
const server = new WebpackDevServer(webpack(webpackConfig), {
hot: true,
historyApiFallback: true
});
server.listen(3000, 'localhost', function (error, result) {
if (error) {
return console.log(err);
}
console.log('Listening at http://localhost:3000/');
});
});
/**
* Run production build.
*/
gulp.task('build-production', (callback) => {
const webpackConfig = require('./webpack.prod.config');
process.env.BABEL_ENV = 'production';
webpack(webpackConfig, function(err, stats) {
delete process.env.BABEL_ENV;
callback();
});
});