-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from callmecavs/build-system
upgrade build system
- Loading branch information
Showing
5 changed files
with
145 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters