-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite as ES6 module and update build pipeline
- Loading branch information
Showing
36 changed files
with
949 additions
and
7,013 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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"root": true, | ||
"extends": "standard", | ||
"env": { | ||
"jquery": true, | ||
"mocha": true | ||
}, | ||
"rules": { | ||
"space-before-function-paren": 0, | ||
"no-multiple-empty-lines": [2, {"max": 2}] | ||
} | ||
} |
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 |
---|---|---|
@@ -1,8 +1,5 @@ | ||
language: node_js | ||
node_js: | ||
- "0.10" | ||
- "0.12" | ||
- "4.1" | ||
- "5.4" | ||
- "node" | ||
script: | ||
npm run-script build | ||
npm run build |
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
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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,86 @@ | ||
const gulp = require('gulp') | ||
const rollup = require('rollup-stream') | ||
const sourcemaps = require('gulp-sourcemaps') | ||
const source = require('vinyl-source-stream') | ||
const buffer = require('vinyl-buffer') | ||
const rename = require('gulp-rename') | ||
const uglify = require('gulp-uglify') | ||
const mochaPhantomjs = require('gulp-mocha-phantomjs') | ||
const buble = require('gulp-buble') | ||
const del = require('del') | ||
const pump = require('pump') | ||
const eslint = require('gulp-eslint') | ||
|
||
|
||
// clean build folder | ||
gulp.task('clean', () => { | ||
return del([ | ||
'lib/*' | ||
]) | ||
}) | ||
|
||
// lint 'em files | ||
gulp.task('lint', () => { | ||
return gulp.src(['src/*.js', 'tests/*.js']) | ||
.pipe(eslint()) | ||
.pipe(eslint.format()) | ||
.pipe(eslint.failAfterError()) | ||
}) | ||
|
||
// compile to es2015 but leave the import/exports intact | ||
gulp.task('compile', ['lint'], () => { | ||
return gulp.src('./src/index.js') | ||
.pipe(sourcemaps.init()) | ||
.pipe(buble({ | ||
transforms: { | ||
modules: false | ||
} | ||
})) | ||
.pipe(rename('isInViewport.es6.js')) | ||
.pipe(sourcemaps.write('.')) | ||
.pipe(gulp.dest('lib')) | ||
}) | ||
|
||
// bundle it | ||
gulp.task('rollup', ['compile'], () => { | ||
return rollup({ | ||
entry: './lib/isInViewport.es6.js', | ||
format: 'umd', | ||
moduleId: 'isInViewport', | ||
moduleName: 'isInViewport', | ||
globals: { | ||
jquery: '$', | ||
window: 'window' | ||
}, | ||
external: ['jquery', 'window'] | ||
}) | ||
.pipe(source('isInViewport.es6.js', './lib')) | ||
.pipe(buffer()) | ||
.pipe(sourcemaps.init({loadMaps: true})) | ||
.pipe(rename('isInViewport.js')) | ||
.pipe(sourcemaps.write('.')) | ||
.pipe(gulp.dest('lib')) | ||
}) | ||
|
||
// minify it | ||
gulp.task('minify', ['rollup'], (cb) => { | ||
pump([ | ||
gulp.src('./lib/isInViewport.js'), | ||
sourcemaps.init({loadMaps: true}), | ||
uglify({ | ||
preserveComments: (_, {type, value: text}) => type === 'comment2' && /@(author|license)/g.test(text) | ||
}), | ||
rename('isInViewport.min.js'), | ||
sourcemaps.write('.'), | ||
gulp.dest('lib') | ||
], cb) | ||
}) | ||
|
||
// test the transpiled, minified bundle | ||
gulp.task('test', ['minify'], () => { | ||
return gulp.src('./tests/tests.html') | ||
.pipe(mochaPhantomjs()) | ||
.on('error', () => gulp.start('clean')) // remove built files if tests fail | ||
}) | ||
|
||
gulp.task('default', ['clean', 'test']) |
Oops, something went wrong.