forked from cncjs/cncjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
117 lines (107 loc) · 2.98 KB
/
app.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
import fs from 'fs';
import path from 'path';
import gulp from 'gulp';
import babel from 'gulp-babel';
import gutil from 'gulp-util';
import webpack from 'webpack';
const NODE_MODULES = path.resolve(__dirname, '../../node_modules');
// http:https://jlongster.com/Backend-Apps-with-Webpack--Part-I
const externals = {};
fs.readdirSync(NODE_MODULES)
.filter((x) => {
return ['.bin'].indexOf(x) === -1;
})
.forEach((mod) => {
externals[mod] = 'commonjs ' + mod;
});
const webpackProductionConfig = {
target: 'node',
context: path.resolve(__dirname, '../../src/app'),
entry: {
index: [
'./index.js'
]
},
output: {
path: path.join(__dirname, '../../dist/cncjs/app'),
filename: '[name].js',
libraryTarget: 'commonjs2'
},
plugins: [
new webpack.optimize.OccurrenceOrderPlugin()
],
module: {
loaders: [
{
test: /\.json$/,
loader: 'json'
},
{
test: /\.jsx?$/,
loader: 'babel',
exclude: /node_modules/,
query: {
presets: ['es2015', 'stage-0', 'react']
}
}
]
},
externals: externals,
resolve: {
extensions: ['', '.js', '.jsx']
},
resolveLoader: {
modulesDirectories: [
NODE_MODULES
]
},
node: {
console: true,
global: true,
process: true,
Buffer: true,
__filename: true, // Use relative path
__dirname: true, // Use relative path
setImmediate: true
}
};
const distConfig = {
base: 'src/app',
src: [
'src/app/{i18n,views}/**/*'
],
dest: 'dist/cncjs/app'
};
export default (options) => {
gulp.task('app:build-dev', (callback) => {
if (process.env.NODE_ENV !== 'development') {
const err = new Error('Set NODE_ENV to "development" for development build');
throw new gutil.PluginError('app:build-dev', err);
}
const src = [
'src/app/**/*.js'
// exclusion
];
return gulp.src(src)
.pipe(babel())
.pipe(gulp.dest('dist/cncjs/app'));
});
gulp.task('app:build-prod', (callback) => {
if (process.env.NODE_ENV !== 'production') {
const err = new Error('Set NODE_ENV to "production" for production build');
throw new gutil.PluginError('app:build', err);
}
webpack(webpackProductionConfig, (err, stats) => {
if (err) {
throw new gutil.PluginError('app:build', err);
}
gutil.log('[app:build]', stats.toString({ colors: true }));
callback();
});
});
gulp.task('app:i18n', ['i18next:app']);
gulp.task('app:dist', () => {
return gulp.src(distConfig.src, { base: distConfig.base })
.pipe(gulp.dest(distConfig.dest));
});
};