forked from them-es/starter-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
executable file
·107 lines (92 loc) · 1.85 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
const gulp = require( 'gulp' ),
fancylog = require( 'fancy-log' ),
browserSync = require( 'browser-sync' ),
server = browserSync.create(),
dev_url = 'http://localhost/starter-material';
/**
* Define all source paths
*/
var paths = {
styles: {
src: './assets/*.scss',
dest: './assets/css'
},
scripts: {
src: './assets/*.js',
dest: './assets/js'
}
};
/**
* Webpack compilation: http://webpack.js.org, https://github.com/shama/webpack-stream#usage-with-gulp-watch
*
* build_js()
*/
function build_js() {
const compiler = require( 'webpack' ),
webpackStream = require( 'webpack-stream' );
return gulp.src( paths.scripts.src )
.pipe(
webpackStream({
config: require( './webpack.config.js' )
},
compiler
)
)
.pipe(
gulp.dest( paths.scripts.dest )
)
/*.pipe(
server.stream() // Browser Reload
)*/;
}
/**
* SASS-CSS compilation: https://www.npmjs.com/package/gulp-sass
*
* build_css()
*/
function build_css() {
const sass = require( 'gulp-sass' ),
postcss = require( 'gulp-postcss' ),
sourcemaps = require( 'gulp-sourcemaps' ),
autoprefixer = require( 'autoprefixer' ),
cssnano = require( 'cssnano' );
const plugins = [
autoprefixer(),
cssnano(),
];
return gulp.src( paths.styles.src )
.pipe(
sourcemaps.init()
)
.pipe(
sass()
.on( 'error', sass.logError )
)
.pipe(
postcss(plugins)
)
.pipe(
sourcemaps.write( './' )
)
.pipe(
gulp.dest( paths.styles.dest )
)
/*.pipe(
server.stream() // Browser Reload
)*/;
}
/**
* Watch task: Webpack + SASS
*
* $ gulp watch
*/
gulp.task('watch',
function () {
// Modify "dev_url" constant and uncomment "server.init()" to use browser sync
/*server.init({
proxy: dev_url,
} );*/
gulp.watch( paths.scripts.src, build_js );
gulp.watch( [ paths.styles.src, './assets/scss/*.scss' ], build_css );
}
);