1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | var minimatch = require('minimatch');
|
8 | var combiner = require('stream-combiner2');
|
9 |
|
10 | function minimatchTester(rules, path) {
|
11 | var match = false
|
12 | if (Array.isArray(rules)) {
|
13 | rules.map(function(rule) {
|
14 | if (minimatch(path, rule, { nonegate: true })) {
|
15 | match = true
|
16 | }
|
17 | })
|
18 | } else {
|
19 | match = minimatch(rules, path, { nonegate: true })
|
20 | }
|
21 |
|
22 | return match
|
23 | }
|
24 |
|
25 | module.exports = function(gulp, $, conf, browserSync) {
|
26 | var gs = $.sync(gulp);
|
27 |
|
28 | gulp.task('serve', gs.sync([
|
29 | 'clean:tmp',
|
30 | ['scripts', 'styles', 'template'],
|
31 | ['rollup']
|
32 | ]), function() {
|
33 |
|
34 | $.watch(conf.parsePwd(conf.stylesFiles4Watch), function(evt) {
|
35 | conf.gwChangeHandler(evt);
|
36 | process.env.styleFile = minimatchTester(conf.parsePwd(conf.styleFiles), evt.path) ? evt.path : '';
|
37 | gulp.start('styles');
|
38 | });
|
39 |
|
40 |
|
41 | $.watch(conf.parsePwd(conf.scriptFiles4Watch), (evt) => {
|
42 | conf.gwChangeHandler(evt)
|
43 | gulp.start(gs.sync(['scripts', 'rollup']));
|
44 | });
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 | $.watch(conf.parsePwd(conf.tmplFiles4Watch), function(evt) {
|
52 | conf.gwChangeHandler(evt);
|
53 | gulp.start('template');
|
54 | });
|
55 |
|
56 |
|
57 | browserSync.init({
|
58 | ui: false,
|
59 | open: "external",
|
60 | startPath: conf.serve.open,
|
61 | port: conf.serve.port,
|
62 | notify: false,
|
63 | ghostMode: false,
|
64 | server: {
|
65 | baseDir: conf.parsePwd([conf.tmp, conf.app]),
|
66 | index: conf.serve.index,
|
67 |
|
68 | middleware: function (req, res, next) {
|
69 | res.setHeader('Access-Control-Allow-Origin', '*');
|
70 | next();
|
71 | }
|
72 | }
|
73 | })
|
74 | });
|
75 |
|
76 |
|
77 | gulp.task('build', gs.sync([
|
78 | ['clean:tmp', 'clean:dist'],
|
79 | ['scripts', 'styles', 'template'],
|
80 | ['rollup'],
|
81 | 'copy:tmp',
|
82 | 'copy:dist'
|
83 | ]));
|
84 | }
|