From f3da583c3272adf61e362f8983d7888820f6b19f Mon Sep 17 00:00:00 2001 From: Gary Green Date: Fri, 19 Apr 2019 22:10:44 +0100 Subject: [PATCH] Use rollup to bundle. --- Sortable.js | 26 ++++++-------------------- gulpfile.js | 45 --------------------------------------------- index-es.js | 7 +++++++ index-iife.js | 3 +++ index.html | 2 +- package.json | 15 +++++++-------- rollup.config.js | 13 +++++++++++++ 7 files changed, 37 insertions(+), 74 deletions(-) delete mode 100644 gulpfile.js create mode 100644 index-es.js create mode 100644 index-iife.js create mode 100644 rollup.config.js diff --git a/Sortable.js b/Sortable.js index eeb0ba4c7..eddab4807 100644 --- a/Sortable.js +++ b/Sortable.js @@ -5,26 +5,12 @@ * @license MIT */ -(function sortableModule(factory) { - "use strict"; +"use strict"; - if (typeof define === "function" && define.amd) { - define(factory); - } - else if (typeof module != "undefined" && typeof module.exports != "undefined") { - module.exports = factory(); - } - else { - /* jshint sub:true */ - window["Sortable"] = factory(); - } -})(function sortableFactory() { - "use strict"; +import { version } from './package.json'; if (typeof window === "undefined" || !window.document) { - return function sortableError() { - throw new Error("Sortable.js requires a window with a document"); - }; + throw new Error("Sortable.js requires a window with a document"); } var dragEl, @@ -2455,6 +2441,6 @@ // Export - Sortable.version = '1.9.0'; - return Sortable; -}); + Sortable.version = version; + + export default Sortable; diff --git a/gulpfile.js b/gulpfile.js deleted file mode 100644 index 8e45f1fdf..000000000 --- a/gulpfile.js +++ /dev/null @@ -1,45 +0,0 @@ -/* jshint ignore:start */ -const gulp = require('gulp'), - uglify = require('gulp-uglify'), - rename = require('gulp-rename'), - each = require('gulp-each'), - path = require('path'), - pump = require('pump') -; - -const package = require('./package.json'), - name = package.exportName, - versionExp = /(?<=\"version\":\s{0,}\")(.{0,})(?=\")/i; - -gulp.task('version', function() { - let version = package.version; - return pump([ - gulp.src('./*.json'), - each(function(content, file, callback){ - let prevVersion = content.match(versionExp); - prevVersion && (prevVersion = prevVersion[0]); - content = content.replace(versionExp, version); - prevVersion && prevVersion !== version && console.info(`Updated version in ${ path.basename(file.history[0]) }:\t${ prevVersion } -> ${ version }`); - callback(null, content); - }), - gulp.dest('./') - ]); -}); - -gulp.task('minify', function() { - return pump([ - gulp.src(`./${ name }.js`), - uglify({ - output: { - preamble: `/*! ${ name } ${ package.version } - ${ package.license } | ${ package.repository.url } */\n` - } - }), - rename({ - suffix: '.min' - }), - gulp.dest(`./`) - ]); -}); - -gulp.task('build', gulp.series('version', 'minify')); -/* jshint ignore:end */ diff --git a/index-es.js b/index-es.js new file mode 100644 index 000000000..52aa405d3 --- /dev/null +++ b/index-es.js @@ -0,0 +1,7 @@ +import Sortable from './Sortable'; + +export default Sortable; + +export { + Sortable +} \ No newline at end of file diff --git a/index-iife.js b/index-iife.js new file mode 100644 index 000000000..8f711ebcc --- /dev/null +++ b/index-iife.js @@ -0,0 +1,3 @@ +import Sortable from './Sortable'; + +export default Sortable; diff --git a/index.html b/index.html index f3c010e33..93457377c 100644 --- a/index.html +++ b/index.html @@ -365,7 +365,7 @@

+ diff --git a/package.json b/package.json index 88ee1f22a..896adb918 100644 --- a/package.json +++ b/package.json @@ -3,18 +3,17 @@ "exportName": "Sortable", "version": "1.9.0", "devDependencies": { - "gulp": "^4.0.0", - "gulp-each": "^0.5.0", - "gulp-rename": "^1.4.0", - "gulp-uglify": "^3.0.1", - "http-server": "^0.9.0", - "pump": "^3.0.0" + "rollup": "^1.10.1", + "uglify-js": "^3.5.5" }, "description": "JavaScript library for reorderable drag-and-drop lists on modern browsers and touch devices. No jQuery required. Supports Meteor, AngularJS, React, Polymer, Vue, Knockout and any CSS library, e.g. Bootstrap.", "main": "Sortable.js", + "module": "index-es.js", "scripts": { - "http-server": "http-server -s ./", - "prepublish": "gulp build" + "prepublish": "npm run build", + "build": "rollup -c rollup.config.js && npm run min", + "min": "uglifyjs -mangle --comments=/@license/ -o dist/sortable.min.js -- dist/sortable.js", + "watch": "npm run build -- --watch" }, "maintainers": [ "Konstantin Lebedev ", diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 000000000..2bec24110 --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,13 @@ +import json from 'rollup-plugin-json'; + +export default [ + { + input: 'index-iife.js', + output: { + file: 'dist/sortable.js', + format: 'iife', + name: 'Sortable' + }, + plugins: [json()] + } +];