Skip to content

Commit 1b8916e

Browse files
author
jfusco
committed
Clean u gulp build files
Remove stage-2 from babelrc and add stage-0 so we can take advantage of function binding. Add global object in eslint and add __DEV__ and module Add gulp load plugins to the build to allow auto loading of plguins Separate out tasks in a gulp/tasks folder for separation of concerns and scalability. Add bridge.js file to load all plugins and pass appropriate settings to each task. Add gulp util for coloration and beepbeep for notification once the build is done. Add webpack progress bar plugin so we can see the status of a distribution build when webpack is running. Refactor gulpfile.babel.js to use gulp load plugins and update the tasks to use utils Add __DEV__ to webpack so we can easliy decide which code gets ripped out when doing prod builds Add exmaple of using __DEV__ in Github.js class
1 parent 590ccaa commit 1b8916e

17 files changed

Lines changed: 231 additions & 190 deletions

.babelrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"presets": [
33
"es2015",
4-
"stage-2"
4+
"stage-0"
55
],
66
"plugins": [
77
["transform-runtime", {

.eslintrc.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,9 @@ module.exports = {
1010
extends: 'standard',
1111
rules: {
1212
'space-before-function-paren': 0
13+
},
14+
globals: {
15+
'__DEV__': true,
16+
'module': true
1317
}
1418
}

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
.idea
2-
dist
3-
node_modules
1+
/.idea
2+
/dist
3+
/node_modules
44
npm-debug.log
55
*.sublime-project
66
*.sublime-workspace

gulp/bridge.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = (gulp, tasks, $, server) => {
2+
tasks.forEach(name => {
3+
require('./tasks/' + name)(gulp, $, server)
4+
})
5+
}

gulp/tasks/clean.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Clean our dist folder before building.
3+
*/
4+
module.exports = (gulp, $) => {
5+
gulp.task('clean', () => {
6+
$.del(['dist'], {
7+
force: true
8+
})
9+
.then(paths => {
10+
$.util.log($.util.colors.green.bold(`Deleted files and folders: ${paths.join('\n')}`))
11+
})
12+
})
13+
}

gulp/tasks/fonts.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Copy font files into dist on build.
3+
*/
4+
module.exports = (gulp, $, server) => {
5+
gulp.task('fonts', () => {
6+
return gulp.src([
7+
'src/fonts/**/*.{woff,woff2,eot,ttf,otf,svg}',
8+
'node_modules/font-awesome/fonts/**/*.{woff,woff2,eot,ttf,otf,svg}'
9+
])
10+
.pipe($.plumber())
11+
.pipe(gulp.dest('dist/fonts'))
12+
.pipe(server.stream())
13+
})
14+
}

gulp/tasks/html.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Render html files and copy into dist on build.
3+
*/
4+
module.exports = (gulp, $, server) => {
5+
gulp.task('html', () => {
6+
return gulp.src('src/**/*.html')
7+
.pipe($.plumber())
8+
.pipe($.fileInclude({
9+
prefix: '@@',
10+
basepath: 'src'
11+
}))
12+
.pipe(gulp.dest('dist'))
13+
.pipe(server.stream({reload: true}))
14+
})
15+
}

gulp/tasks/images.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const isProduction = process.env.NODE_ENV === 'production'
2+
3+
/**
4+
* Minify and copy our images into dist on build.
5+
*/
6+
module.exports = (gulp, $, server) => {
7+
gulp.task('images', () => {
8+
return gulp.src([
9+
'src/img/**',
10+
'!src/img/sprites{,/**}'
11+
])
12+
.pipe($.plumber())
13+
.pipe($.if(isProduction, $.imagemin()))
14+
.pipe(gulp.dest('dist/img'))
15+
.pipe(server.stream())
16+
})
17+
}

gulp/tasks/server.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import webpack from 'webpack'
2+
import webpackDevMiddleware from 'webpack-dev-middleware'
3+
import webpackHotMiddleware from 'webpack-hot-middleware'
4+
import webpackConfig from '../../webpack.config.babel'
5+
6+
/**
7+
* The development server.
8+
*/
9+
module.exports = (gulp, $, server) => {
10+
gulp.task('server', ['build'], done => {
11+
const bundler = webpack(webpackConfig)
12+
13+
server.init({
14+
notify: false,
15+
logLevel: 'none',
16+
server: {
17+
baseDir: 'dist',
18+
middleware: [
19+
webpackDevMiddleware(bundler, webpackConfig.devServer),
20+
webpackHotMiddleware(bundler)
21+
]
22+
}
23+
}, done)
24+
})
25+
}

gulp/tasks/sprite.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Creates a spritesheet from our img/sprites folder.
3+
*/
4+
module.exports = (gulp, $, server) => {
5+
gulp.task('sprite', () => {
6+
return gulp.src('src/img/sprites/**/*')
7+
.pipe($.plumber())
8+
.pipe($.spritesmith({
9+
imgName: 'img/sprite.png',
10+
cssName: 'scss/_sprite.scss'
11+
}))
12+
.pipe(gulp.dest('src'))
13+
.pipe(server.stream())
14+
})
15+
}

0 commit comments

Comments
 (0)