/
gulpfile.js
122 lines (112 loc) · 3 KB
/
gulpfile.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
118
119
120
121
122
/*
* AngularJS TableTools Plugin
* Copyright (c) 2016-2021 Rodziu <mateusz.rohde@gmail.com>
* License: MIT
*/
!function() {
'use strict';
const gulp = require('gulp'),
rename = require('gulp-rename'),
ts = require('gulp-typescript'),
sourcemaps = require('gulp-sourcemaps'),
eslint = require('gulp-eslint'),
ngAnnotate = require('@rodziu/gulp-ng-annotate-patched'),
embedTemplates = require('gulp-angular-embed-templates'),
plumber = require('gulp-plumber'),
log = require('fancy-log'),
merge = require('merge2'),
webpack = require('webpack'),
webpackStream = require('webpack-stream');
// ts
gulp.task('ts', () => {
const tsProject = ts.createProject('tsconfig.json'),
tsResult = gulp.src([
'src/ts/**/*.ts',
])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failOnError())
.pipe(sourcemaps.init())
.pipe(tsProject());
return merge([
tsResult.dts.pipe(gulp.dest('dist')),
tsResult.js
.pipe(plumber())
.pipe(ngAnnotate().on('error', (e) => {
log('\x1b[31mngAnnotate\x1b[0m ', e.message);
}))
.pipe(plumber.stop())
.pipe(embedTemplates({basePath: __dirname}))
.pipe(sourcemaps.write())
.pipe(gulp.dest('.build'))
]);
});
gulp.task('bundle', () => {
return _bundle(false);
});
gulp.task('bundle:prod', () => {
return _bundle(true);
});
function _bundle(production) {
return gulp.src('dummy', {allowEmpty: true})
.pipe(webpackStream({
entry: {
'angularjs-bootstrap4-table-tools': './.build/angularjs-bootstrap4-table-tools.js'
},
mode: production ? 'production' : 'development',
externals: {
angular: 'angular',
'angularjs-bootstrap-4': 'angularjs-bootstrap-4'
},
output: {
devtoolNamespace: 'tableTools',
filename: (pathData) => {
let name = pathData.chunk.name;
return name.substring(0, 1).toLowerCase()
+ name.substring(1).replace(/[A-Z]/g, (letter) => {
return '-' + letter.toLowerCase();
})
+ (production ? '.min' : '') + '.js'
},
library: '[name]',
libraryTarget: 'umd',
libraryExport: 'default',
umdNamedDefine: true,
globalObject: 'window'
},
module: {
rules: [
{
test: /\.js$/,
enforce: 'pre',
use: ['source-map-loader'],
},
],
},
devtool: 'source-map'
}, webpack))
.pipe(gulp.dest('dist'));
}
// css
const cssMin = require('gulp-clean-css'),
sass = require('gulp-sass');
gulp.task('scss', function() {
return gulp.src('src/scss/*.scss')
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(gulp.dest('dist'))
.pipe(rename({suffix: '.min'}))
.pipe(cssMin())
.pipe(sourcemaps.write('./', {includeContent: false}))
.pipe(gulp.dest('dist'));
});
gulp.task('watch', function() {
[
['src/**/*.ts', 'ts'],
['src/**/.scss', 'scss']
].forEach(([src, task]) => {
gulp.watch(src, {}, gulp.series(task, 'bundle', 'bundle:prod'));
});
});
exports.default = gulp.series('ts', 'scss', 'bundle', 'bundle:prod');
}();