forked from open-duelyst/duelyst
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbundler.js
114 lines (103 loc) · 3.23 KB
/
bundler.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
import path from 'path';
import gulp from 'gulp';
import gutil from 'gulp-util';
import gif from 'gulp-if';
import rename from 'gulp-rename';
import uglify from 'uglify-es';
import composer from 'gulp-uglify/composer';
import notify from 'gulp-notify';
// Browserify
// https://github.com/gulpjs/gulp/blob/master/docs/recipes/fast-browserify-builds-with-watchify.md
import browserify from 'browserify';
import watchify from 'watchify';
import source from 'vinyl-source-stream';
import buffer from 'vinyl-buffer';
import coffeeify from 'coffeeify';
import glslify from 'glslify';
import hbsfy from 'hbsfy';
import envify from 'envify/custom';
import babelify from 'babelify';
import uglifyify from 'uglifyify';
import bundleCollapser from 'bundle-collapser/plugin';
import {
opts, config, env, version, production, staging, development,
} from './shared';
const minify = composer(uglify, console);
// Browserify options
// https://github.com/substack/node-browserify#usage
// if env == 'production' || env == 'staging' then false else true,
const bundlerOpts = {
paths: [path.join(__dirname, '..')],
debug: development,
cache: {},
packageCache: {},
extensions: ['.coffee', '.js'],
// ignoreMissing: true,
// detectGlobals: false
};
const entries = ['./app/index'];
if (config.get('datGuiEditorEnabled')) {
entries.push('./app/tools/editor.coffee');
}
// gutil.log(`bundler options: ${JSON.stringify(opts)}`)
// Initialize bundler
let bundler = browserify(entries, bundlerOpts);
if (opts.watch) {
bundler = watchify(bundler);
}
// Apply bundler transforms
// bundler.transform(aliasify, aliasConfig)
bundler.transform(coffeeify);
bundler.transform(hbsfy);
bundler.transform(glslify);
bundler.transform(envify({
NODE_ENV: env,
VERSION: version,
API_URL: config.get('api'),
FIREBASE_URL: config.get('firebase.url'),
ALL_CARDS_AVAILABLE: config.get('allCardsAvailable'),
AI_TOOLS_ENABLED: config.get('aiToolsEnabled'),
RECORD_CLIENT_LOGS: config.get('recordClientLogs'),
INVITE_CODES_ACTIVE: config.get('inviteCodesActive'),
RECAPTCHA_ACTIVE: config.get('recaptcha.enabled'),
BUGSNAG_WEB: config.get('bugsnag.web_key'),
BUGSNAG_DESKTOP: config.get('bugsnag.desktop_key'),
TRACKING_PIXELS_ENABLED: false,
LANDING_PAGE_URL: '/',
REFERRER_PAGE_URLS: '',
}));
// bundler.transform(babelify, {
// compact: false
// })
if (opts.minify) {
gutil.log('[BROWSERIFY] Minifying bundle');
bundler.transform(uglifyify);
// bundler.plugin(bundleCollapser)
}
// Re-bundle on update
bundler.on('update', bundle);
// Log bundler updates
bundler.on('update', (files) => {
gutil.log('[BROWSERIFY] Bundle updating');
files.map((file) => gutil.log(` [CHANGED] ${file}`));
});
// Log bundler output
bundler.on('log', gutil.log.bind(gutil, '[BROWSERIFY]'));
// export bundle function
export default function bundle() {
return bundler.bundle()
// log errors if they happen
.on('error', (e) => {
gutil.log(`[BROWSERIFY] Error: ${e.message}`);
notify.onError('Error: <%= error.message %>');
})
.pipe(source('index.js'))
.pipe(buffer())
.pipe(gif(opts.minify, minify({ mangle: true })))
.pipe(rename((p) => {
p.basename = 'duelyst';
return p.basename;
}))
.pipe(notify())
.pipe(gulp.dest('dist/src'));
}