-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
101 lines (91 loc) · 2.39 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
const gulp = require('gulp');
const sass = require('gulp-sass');
const autoprefixer = require('autoprefixer');
const postcss = require('gulp-postcss');
const rename = require('gulp-rename');
const babelify = require('babelify');
const browserify = require('browserify');
const source = require('vinyl-source-stream');
const uglify = require('gulp-uglify');
const buffer = require('vinyl-buffer');
const sassLint = require('gulp-sass-lint');
const eslint = require('gulp-eslint');
const cleanCSS = require('gulp-clean-css');
const paths = {
src: './src',
build: './dist',
};
const config = {
projectName: 'luma',
uglify: {
src: `${paths.src}/js/*.js`,
dest: paths.build,
options: {},
},
browserify: {
entries: [`${paths.src}/js/index.js`],
standalone: 'luma',
},
babelify: {
presets: ['es2015'],
},
sass: `${paths.src}/scss/**/*.scss`,
sass_exclude: `!${paths.src}/scss/base/_normalize.scss, !${paths.src}/vendor/*.scss`,
scripts: `${paths.src}/js/*.js`,
};
/**
* Run all tasks needed for a build.
*/
gulp.task('build', ['sass', 'scripts']);
/**
* Default task. Run the watch task
*/
gulp.task('default', ['watch']);
/**
* Run the build task and then start watching for changes.
*/
gulp.task('watch', ['build'], () => {
gulp.watch(config.sass, ['sass']);
gulp.watch(config.scripts, ['scripts']);
});
/**
* Compile Sass, run autoprefixer and minify the outcome.
*/
gulp.task('sass', ['sass:lint'], () => {
return gulp.src(`${paths.src}/scss/*.scss`)
.pipe(sass())
.pipe(postcss([autoprefixer()]))
.pipe(cleanCSS())
.pipe(rename(`${config.projectName}.min.css`))
.pipe(gulp.dest(paths.build));
});
/**
* Lint SCSS files
*/
gulp.task('sass:lint', () => {
return gulp.src([config.sass, config.sass_exclude])
.pipe(sassLint())
.pipe(sassLint.format())
.pipe(sassLint.failOnError());
});
/**
* Compile ES6 Javascript and bundle it together.
*/
gulp.task('scripts', () => {
return browserify(config.browserify)
.transform(babelify.configure(config.babelify))
.bundle()
.pipe(source(`${config.projectName}.min.js`))
.pipe(buffer())
// .pipe(uglify())
.pipe(gulp.dest(paths.build));
});
/**
* Lint Javascript files with ESLint
*/
gulp.task('scripts:lint', () => {
return gulp.src([config.scripts, `!${config.scripts}/vendor`])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});