forked from Wikiki/bulma-quickview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
180 lines (167 loc) · 5.11 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
const pkg = require('./package.json');
const gulp = require('gulp');
const webpack = require('webpack');
const webpackStream = require('webpack-stream');
const autoprefixer = require('autoprefixer');
const camelCase = require('camelcase');
const cleancss = require('gulp-clean-css');
const colors = require('ansi-colors');
const concat = require('gulp-concat');
const del = require('del');
const fs = require('fs');
const log = require('fancy-log');
const nop = require('gulp-nop');
const postcss = require('gulp-postcss');
const sass = require('gulp-sass');
const uglify = require('gulp-uglify');
/**
* ----------------------------------------
* VARIABLES
* ----------------------------------------
*/
const paths = {
src: 'src/',
dist: 'dist/',
bulma: 'node_modules/bulma/sass/utilities/'
};
const config = {
sass: {
input: 'index.sass',
dependencies: ['node_modules/bulma/sass/utilities/_all.sass'],
output: {
filename: pkg.name,
format: 'compressed'
},
source: paths.src + 'sass/',
destination: paths.dist + 'css/'
},
javascript: {
input: 'index.js',
output: {
name: camelCase(pkg.name),
filename: pkg.name,
format: 'umd'
},
source: paths.src + 'js/',
destination: paths.dist + 'js/'
}
};
/**
* ----------------------------------------
* BUILD STYLESHEETS TASKS
* ----------------------------------------
*/
// Uses Sass compiler to process styles, adds vendor prefixes, minifies, then
// outputs file to the appropriate location.
gulp.task('build:styles', function() {
if (fs.existsSync(config.sass.source + config.sass.input)) {
return gulp
.src(config.sass.dependencies.concat([config.sass.source + config.sass.input]))
.pipe(concat(config.sass.output.filename + '.sass'))
.pipe(sass({
style: config.sass.output.format,
trace: true,
loadPath: [config.sass.source],
includePaths: ['node_modules/bulma/sass/utilities/']
}))
.pipe(concat(config.sass.output.filename + (config.sass.output.format === 'compressed' ? '.min' : '') + '.css'))
.pipe(postcss([autoprefixer({browsers: pkg.broswers})]))
.pipe(cleancss())
.pipe(gulp.dest(config.sass.destination));
} else {
return gulp.src('.').pipe(nop());
}
});
// Copy original sass file to dist
gulp.task('build:styles:copy', function() {
if (fs.existsSync(config.sass.source + config.sass.input)) {
return gulp.src(config.sass.source + config.sass.input)
.pipe(concat(config.sass.output.filename + '.sass'))
.pipe(gulp.dest(config.sass.destination));
} else {
return gulp.src('.').pipe(nop());
}
});
gulp.task('clean:styles', function() {
return del([
config.sass.destination + config.sass.output.filename + '.sass',
config.sass.destination + config.sass.output.filename + (config.sass.output.format === 'compressed' ? '.min' : '') + '.css'
]);
});
/**
* ----------------------------------------
* BUILD JAVASCRIPT TASKS
* ----------------------------------------
*/
// Concatenates and uglifies global JS files and outputs result to the
// appropriate location.
gulp.task('build:scripts', function() {
if (fs.existsSync(config.javascript.source + config.javascript.input)) {
return gulp
.src(config.javascript.source + config.javascript.input)
.pipe(webpackStream({
output: {
filename: config.javascript.output.filename + '.js',
library: config.javascript.output.name,
libraryTarget: config.javascript.output.format,
libraryExport: 'default'
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /(node_modules)/,
loader: 'babel-loader',
options: {
babelrc: './babelrc'
}
},
],
}
}), webpack)
.pipe(concat(config.javascript.output.filename + '.js'))
.pipe(gulp.dest(config.javascript.destination))
.pipe(concat(config.javascript.output.filename + '.min.js'))
.pipe(uglify().on('error', function(err) {
log(colors.red('[Error]'), err.toString());
}))
.pipe(gulp.dest(config.javascript.destination)
.on('error', function(err) {
log(colors.red('[Error]'), err.toString());
})
);
} else {
return gulp.src('.').pipe(nop());
}
});
gulp.task('clean:scripts', function() {
return del([
config.javascript.destination + config.javascript.output.filename + '.js',
config.javascript.destination + config.javascript.output.filename + '.min.js'
]);
});
/**
* ----------------------------------------
* GLOBAL CLEAN
* ----------------------------------------
*/
// Deletes the entire dist directory.
gulp.task('clean', function() {
return del(paths.dist);
});
/**
* ----------------------------------------
* GLOBAL BUILD
* ----------------------------------------
*/
gulp.task('build', gulp.series('clean', 'build:styles', 'build:styles:copy', 'build:scripts', function(callback) {
callback();
}));
/**
* ----------------------------------------
* DEFAULT TASK
* ----------------------------------------
*/
gulp.task('default', gulp.series('build', function(done) {
done();
}));