-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
70 lines (66 loc) · 2.06 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
const gulp = require('gulp');
const browserify = require('browserify');
const source = require('vinyl-source-stream');
const stylus = require('gulp-stylus');
const rename = require('gulp-rename');
const mincss = require('gulp-clean-css');
const buffer = require('vinyl-buffer');
const uglify = require('gulp-uglify');
const sourcemaps = require('gulp-sourcemaps');
const browserSync = require('browser-sync').create();
const php = require('gulp-connect-php');
const nib = require('nib');
const fontAwesome = require('fa-stylus');
const app = require('./package.json');
const pathScripts = 'app/scripts/';
const pathStyles = 'app/styles/';
const inject = require('gulp-js-html-inject');
gulp.task('css', () => {
return gulp.src(pathStyles + 'app.styl')
.pipe(sourcemaps.init())
.pipe(stylus({
'use': [nib(), fontAwesome()],
'import': ['nib'],
'include css': true
}))
.pipe(mincss())
.pipe(rename(app.name + '.min.css'))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('public/css/'))
.pipe(browserSync.stream());
});
gulp.task('js', () => {
return browserify({
'entries': pathScripts + 'app.js',
'debug': true
})
.transform('babelify', {
presets: ['@babel/preset-env'],
plugins: [
["@babel/plugin-proposal-decorators", { "legacy" : true }]
]
})
.bundle()
.pipe(source(app.name + '.min.js'))
.pipe(buffer())
.pipe(sourcemaps.init())
.pipe(inject({basepath: pathScripts, pattern: /'import:([a-zA-Z0-9\-_.\/]+)'/g}))
.pipe(uglify())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('public/js/'))
.pipe(browserSync.stream());
});
gulp.task('default', gulp.parallel('css', 'js'));
gulp.task('dev', gulp.parallel('default', () => {
php.server({
router: './app/router.php',
hostname: '0.0.0.0'
}, function (){
browserSync.init(['**/*.php'], {
proxy: process.env.PHP_HOST || 'http://localhost:8000',
port: 8001
});
});
gulp.watch(pathStyles + '**/*', {interval: 1000, usePolling: true}, gulp.series('css'));
gulp.watch(pathScripts + '**/*', {interval: 1000, usePolling: true}, gulp.series('js'));
}));