-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgulpfile.babel.js
More file actions
94 lines (84 loc) · 2.34 KB
/
gulpfile.babel.js
File metadata and controls
94 lines (84 loc) · 2.34 KB
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
import webpack from "webpack";
import gulp from "gulp";
import pkg from "./package.json";
import path from "path";
import WrapperPlugin from "wrapper-webpack-plugin";
import UglifyJSPlugin from "uglifyjs-webpack-plugin";
import Jasmine from "jasmine";
// since webpack 4.0, webpack is built with UglifyJSPlugin if its mode is production.
var webpackConfig = {
version: pkg.version,
name: pkg.name,
entry: "src/index.js",
build(options) {
let { mode = "none" } = options || {};
let isDev = mode !== "production";
let outputFilename = `${this.name}.js`;
let outputPath = path.join(__dirname, isDev ? "build" : "dist");
let plugins = [
new WrapperPlugin({
header: `// ${pkg.name} v${
pkg.version
} ${new Date().toDateString()} \n`
})
];
if (!isDev) {
plugins.unshift(new UglifyJSPlugin());
}
return {
mode: "none", // it should not set mode into production, because the builtin uglifyjs plugin would remove header from bundle file that is added by WrapperPlugin.
output: {
path: outputPath,
filename: outputFilename,
library: "ArmorPubSub",
libraryTarget: "umd",
globalObject: 'typeof self !== "undefined" ? self : this'
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
query: {
presets: [["es2015", { loose: true }]]
}
}
}
]
},
plugins
};
},
release() {
return this.build({ mode: "production" });
}
};
function webpackRunner(options) {
let { release } = options || {};
return new Promise((resolve, reject) => {
webpack(webpackConfig[release ? "release" : "build"](), (err, status) => {
if (err) {
reject(err);
} else {
resolve(status);
}
});
});
}
gulp.task("release", () => webpackRunner({ release: true }));
gulp.task("default", () => webpackRunner());
gulp.task("test", cb => {
let jasmine = new Jasmine();
jasmine.loadConfigFile("spec/support/jasmine.json");
jasmine.onComplete(passed => {
if (passed) {
console.log("All specs have passed");
} else {
console.log("At least one spec has failed");
}
cb();
});
jasmine.execute();
});