UNPKG

2.57 kBJavaScriptView Raw
1'use strict';
2
3// We aren't abstracting this yet but here's the ... "Config"
4const _CONFIG = (
5 {
6 // The input source file that should be passed to browserify:
7 // (if you need to auto-instantiate an object, for instance)
8 EntrypointInputSourceFile: `${__dirname}/source/Foxhound-Browser-Shim.js`,
9
10 // The name of the packaged object to be passed to browserify:
11 // (browserify sets this to global scope and window.SOMEOBJECTNAMEHERE where SOMEOBJECTNAMEHERE is the string below)
12 LibraryObjectName: `Foxhound`,
13
14 // The folder to write the library files and maps out to:
15 LibraryOutputFolder: `${__dirname}/dist/`,
16
17 // The name of the unminified version of the packaged library, for easy debugging:
18 LibraryUniminifiedFileName: `foxhound.js`,
19
20 // The name of the minified version of the packaged library, for production release:
21 LibraryMinifiedFileName: `foxhound.min.js`
22 });
23
24// ---> Boilerplate Browser Uglification and Packaging <--- \\
25
26const libBrowserify = require('browserify');
27const libGulp = require('gulp');
28
29const libVinylSourceStream = require('vinyl-source-stream');
30const libVinylBuffer = require('vinyl-buffer');
31
32const libSourcemaps = require('gulp-sourcemaps');
33const libGulpUtil = require('gulp-util');
34const libBabel = require('gulp-babel');
35const libTerser = require('gulp-terser');
36
37// Build the module for the browser
38libGulp.task('minified',
39() => {
40 // set up the custom browserify instance for this task
41 var tmpBrowserify = libBrowserify(
42 {
43 entries: _CONFIG.EntrypointInputSourceFile,
44 standalone: _CONFIG.LibraryObjectName,
45 debug: true
46 });
47
48 return tmpBrowserify.bundle()
49 .pipe(libVinylSourceStream(_CONFIG.LibraryMinifiedFileName))
50 .pipe(libVinylBuffer())
51 .pipe(libSourcemaps.init({loadMaps: true}))
52 // Add transformation tasks to the pipeline here.
53 .pipe(libBabel())
54 .pipe(libTerser())
55 .on('error', libGulpUtil.log)
56 .pipe(libSourcemaps.write('./'))
57 .pipe(libGulp.dest(_CONFIG.LibraryOutputFolder));
58});
59
60// Build the module for the browser
61libGulp.task('debug',
62 () => {
63 // set up the custom browserify instance for this task
64 var tmpBrowserify = libBrowserify(
65 {
66 entries: _CONFIG.EntrypointInputSourceFile,
67 standalone: _CONFIG.LibraryObjectName,
68 debug: true
69 });
70
71 return tmpBrowserify.bundle()
72 .pipe(libVinylSourceStream(_CONFIG.LibraryUniminifiedFileName))
73 .pipe(libVinylBuffer())
74 .pipe(libBabel())
75 .on('error', libGulpUtil.log)
76 .pipe(libGulp.dest(_CONFIG.LibraryOutputFolder));
77 });
78
79libGulp.task
80(
81 'build',
82 libGulp.series('debug', 'minified')
83);
\No newline at end of file