UNPKG

pressure

Version:

Pressure is a lightweight JavaScript library for both Force Touch and 3D Touch through a single API.

104 lines (96 loc) 3 kB
// include plug-ins var gulp = require('gulp'); var concat = require('gulp-concat'); var umd = require('gulp-umd'); var inject = require('gulp-inject-string') var rename = require('gulp-rename'); var uglify = require('gulp-uglify'); var babel = require('gulp-babel'); var HEADER_COMMENT = '// Pressure v2.2.0 | Created By Stuart Yamartino | MIT License | 2015 - 2020\n'; var DESTINATION = '.'; // JS concat, strip debugging and minify async function build() { gulp.src([ './src/pressure.js', './src/element.js', './src/adapters/adapter.js', './src/adapters/adapter_force_touch.js', './src/adapters/adapter_3d_touch.js', './src/adapters/adapter_pointer.js', './src/config.js', './src/helpers.js', ]) .pipe(concat('dist/pressure.js')) .pipe(babel()) .pipe(umd({ exports: function() { return 'Pressure'; } })) .pipe(inject.prepend(HEADER_COMMENT)) // This will output the non-minified version .pipe(gulp.dest(DESTINATION)) // This will minify and rename to pressure.min.js .pipe(uglify()) .pipe(inject.prepend(HEADER_COMMENT)) .pipe(rename({ extname: '.min.js' })) .pipe(gulp.dest(DESTINATION)); } async function buildJquery() { gulp.src([ './src/jquery_pressure.js', './src/element.js', './src/adapters/adapter.js', './src/adapters/adapter_force_touch.js', './src/adapters/adapter_3d_touch.js', './src/adapters/adapter_pointer.js', './src/config.js', './src/helpers.js', ]) .pipe(concat('dist/jquery.pressure.js')) .pipe(babel()) .pipe(umd({ dependencies: function() { return [ { name: 'jquery', amd: 'jquery', cjs: 'jquery', global: 'jQuery', param: '$' } ] }, /** * The UMD wrapper expects an exports() string for an expression the factory() should return, * and a namespace() string for a global value that should be set when no loader is present. * However, since jquery_pressure.js mutates $ several times instead of returning a value, * it does not need to use these features, so we set them to harmless no-ops. */ namespace: function() { // sets `window.jQuery__pressure` to undefined return 'jQuery__pressure'; }, exports: function() { // safely returns undefined from factory return 'void 0'; } })) .pipe(inject.prepend(HEADER_COMMENT)) // This will output the non-minified version .pipe(gulp.dest(DESTINATION)) // This will minify and rename to jquery.pressure.min.js .pipe(uglify()) .pipe(inject.prepend(HEADER_COMMENT)) .pipe(rename({ extname: '.min.js' })) .pipe(gulp.dest(DESTINATION)); } function watch() { gulp.watch(['src/*', 'src/adapters/*'], build); gulp.watch(['src/*', 'src/adapters/*'], buildJquery); } var dist = gulp.series(build, buildJquery) exports.build = build; exports.buildJquery = buildJquery; exports.watch = watch; exports.dist = dist;