Skip to content

Commit

Permalink
Merge pull request #66 from callmecavs/build-system
Browse files Browse the repository at this point in the history
upgrade build system
  • Loading branch information
callmecavs committed May 8, 2016
2 parents 76bc519 + d80e112 commit 7666da2
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 128 deletions.
4 changes: 2 additions & 2 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"presets": ["es2015"],
"plugins": ["add-module-exports"]
"presets": ["es2015-rollup"],
"plugins": ["transform-object-rest-spread"]
}
4 changes: 2 additions & 2 deletions dist/layzr.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

107 changes: 0 additions & 107 deletions gulpfile.babel.js

This file was deleted.

127 changes: 127 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
// imports

const json = require('./package.json')
const sync = require('browser-sync')
const del = require('del')
const fs = require('fs')
const gulp = require('gulp')
const notifier = require('node-notifier')
const rollup = require('rollup')
const babel = require('rollup-plugin-babel')
const commonjs = require('rollup-plugin-commonjs')
const resolve = require('rollup-plugin-node-resolve')
const uglify = require('rollup-plugin-uglify')

// error handler

const onError = function(error) {
notifier.notify({
'title': 'Error',
'message': 'Compilation failure.'
})

console.log(error)
this.emit('end')
}

// clean

gulp.task('clean', () => del('dist'))

// attribution

const attribution =
`/*!
* Layzr.js ${ json.version } - ${ json.description }
* Copyright (c) ${ new Date().getFullYear() } ${ json.author } - ${ json.homepage }
* License: ${ json.license }
*/
`

// js

const read = {
entry: 'src/layzr.js',
sourceMap: true,
plugins: [
resolve({ jsnext: true }),
babel(),
uglify()
]
}

const write = {
format: 'umd',
exports: 'default',
moduleName: 'Layzr',
sourceMap: true
}

gulp.task('js', () => {
return rollup
.rollup(read)
.then(bundle => {
// generate the bundle
const files = bundle.generate(write)

// cache path to JS dist file
const dist = 'dist/layzr.min.js'

// write the attribution
fs.writeFileSync(dist, attribution)

// write the JS and sourcemap
fs.appendFileSync(dist, files.code)
fs.writeFileSync('dist/maps/layzr.js.map', files.map.toString())
})
})

// server

const server = sync.create()
const reload = sync.reload

const sendMaps = (req, res, next) => {
const filename = req.url.split('/').pop()
const extension = filename.split('.').pop()

if(extension === 'css' || extension === 'js') {
res.setHeader('X-SourceMap', '/maps/' + filename + '.map')
}

return next()
}

const options = {
notify: false,
server: {
baseDir: 'dist',
middleware: [
sendMaps
]
},
watchOptions: {
ignored: '*.map'
}
}

gulp.task('server', () => sync(options))

// watch

gulp.task('watch', () => {
gulp.watch('src/layzr.js', ['js', reload])
})

// build and default tasks

gulp.task('build', ['clean'], () => {
// create dist directories
fs.mkdirSync('dist')
fs.mkdirSync('dist/maps')

// run the tasks
gulp.start('js')
})

gulp.task('default', ['build', 'server', 'watch'])
31 changes: 14 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"name": "layzr.js",
"version": "2.0.4",
"version": "2.1.0",
"description": "A small, fast, and modern library for lazy loading images.",
"homepage": "http://callmecavs.github.io/layzr.js/",
"main": "dist/layzr.min.js",
"jsnext:main": "src/layzr.js",

"author": "Michael Cavalea",
"license": "GPL-3.0",
Expand All @@ -24,24 +25,20 @@
],

"dependencies": {
"knot.js": "^1.0.1"
"knot.js": "^1.1.1"
},

"devDependencies": {
"babel-core": "^6.4.0",
"babel-plugin-add-module-exports": "^0.1.2",
"babel-preset-es2015": "^6.3.13",
"babelify": "^7.2.0",
"browser-sync": "^2.11.0",
"browserify": "^13.0.0",
"gulp": "^3.9.0",
"gulp-header": "^1.7.1",
"gulp-sourcemaps": "^1.6.0",
"gulp-uglify": "^1.5.1",
"lodash.assign": "^4.0.0",
"node-notifier": "^4.4.0",
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.1.0",
"watchify": "^3.7.0"
"babel-preset-es2015-rollup": "*",
"babel-plugin-transform-object-rest-spread": "*",
"browser-sync": "*",
"del": "*",
"gulp": "*",
"node-notifier": "*",
"rollup": "*",
"rollup-plugin-babel": "*",
"rollup-plugin-commonjs": "*",
"rollup-plugin-node-resolve": "*",
"rollup-plugin-uglify": "*"
}
}

0 comments on commit 7666da2

Please sign in to comment.