forked from ngOfficeUIFabric/ng-officeuifabric
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-lib.ts
90 lines (76 loc) · 2.87 KB
/
build-lib.ts
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
'use strict';
import {BaseGulpTask} from '../BaseGulpTask';
import {BuildConfig} from '../../../config/build';
import {Utils} from '../utils';
import * as gulp from 'gulp';
import * as yargs from 'yargs';
import * as webpack from 'webpack';
import * as webpackConfig from '../../../config/webpack';
let $: any = require('gulp-load-plugins')({ lazy: true });
/**
* Builds files to be distributed as a library release.
*
* @class
*/
export class GulpTask extends BaseGulpTask {
/**
* @property {string} description - Help description for the task.
*/
public static description: string = 'Builds ngOfficeUiFabric library files';
/**
* @property {string[]} dependencies - Array of all tasks that should be run before this one.
*/
public static dependencies: string[] = [];
/**
* @property {string[]} aliases - Different options to run the task.
*/
public static aliases: string[] = ['b', 'B'];
/**
* @property {Object} options - Any command line flags that can be passed to the task.
*/
public static options: any = {
'dev': 'Create unminified version of the library with source maps & comments (otherwise, production' + GulpTask.helpMargin +
'bundle created)',
'verbose': 'Output all TypeScript files being compiled & JavaScript files included in the external library',
'version': 'Version number to set build library (if omitted, version from package.json is used)'
};
/**
* @property {ICommandLineArgs} args - Command line arguments;
*/
private _args: ICommandLineArgs = yargs.argv;
/** @constructor */
constructor(done: gulp.TaskCallback) {
super();
Utils.log('Packaging library using webpack');
// load webpack config settings
let config: webpack.Configuration = new webpackConfig.WebPackConfig();
let webpackPlugins: webpack.Plugin[] = [];
// if dev mode, write source maps & keep comments
if (!this._args.dev) {
config.output.filename = BuildConfig.OUTPUT_LIB_NAME + '.min.js';
// use uglify plugin to remove comments & sourcemaps
webpackPlugins.push(
new webpack.optimize.UglifyJsPlugin({
output: {
comments: false
},
sourceMap: false
})
);
} else { // else gen un-uglified & include inline sourcemaps
config.output.filename = BuildConfig.OUTPUT_LIB_NAME + '.js';
config.devtool = 'inline-source-map';
}
// add banner to the generated file
webpackPlugins.push(
new webpack.BannerPlugin(BuildConfig.BANNER_JS, null)
);
// add plugins to config
config.plugins = webpackPlugins;
let rootSource: string = __dirname + '/../../../' + BuildConfig.SOURCE;
// build webpack bundle
return gulp.src([rootSource + '/core/core.ts', rootSource + '/core/components.ts'])
.pipe($.webpack(config))
.pipe(gulp.dest(BuildConfig.OUTPUT_PATH));
}
}