diff --git a/dist/clipboard.js b/dist/clipboard.js index 5c662c4..b57b3aa 100644 --- a/dist/clipboard.js +++ b/dist/clipboard.js @@ -1,614 +1,1206 @@ -(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Clipboard = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;od;d++)c[d].fn.apply(c[d].ctx,b);return this},off:function(a,b){var c=this.e||(this.e={}),d=c[a],e=[];if(d&&b)for(var f=0,g=d.length;g>f;f++)d[f].fn!==b&&e.push(d[f]);return e.length?c[a]=e:delete c[a],this}},b.exports=d},{}],6:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}c.__esModule=!0;var e=function(){function a(a,b){for(var c=0;cr;r++)n[r].fn.apply(n[r].ctx,e);return this},off:function(t,e){var n=this.e||(this.e={}),r=n[t],o=[];if(r&&e)for(var i=0,u=r.length;u>i;i++)r[i].fn!==e&&o.push(r[i]);return o.length?n[t]=o:delete n[t],this}},t.exports=n}])}); \ No newline at end of file diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 0000000..5ede304 --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,18 @@ +var gulp = require('gulp'); +var uglify = require('gulp-uglify'); +var rename = require('gulp-rename'); +var webpack = require('gulp-webpack'); +var concat = require('gulp-concat'); +var browserSync = require('browser-sync'); + +gulp.task('build', function () { + gulp.src('index.js') + .pipe(webpack(require('./webpack.config.js'))) + .pipe(concat('clipboard.js')) + .pipe(gulp.dest('dist')) + .pipe(uglify()) + .pipe(rename({extname: '.min.js' })) + .pipe(gulp.dest('dist')); +}); + +gulp.task('default', ['build']); diff --git a/index.js b/index.js new file mode 100644 index 0000000..126e804 --- /dev/null +++ b/index.js @@ -0,0 +1,11 @@ +import Clipboard from './src/clipboard'; +import ClipboardAction from './src/clipboard-action'; +import DelegateEvents from 'delegate-events'; +import TinyEmitter from 'tiny-emitter'; + +// expose bundled libraries +Clipboard.ClipboardAction = ClipboardAction; +Clipboard.DelegateEvents = DelegateEvents; +Clipboard.TinyEmitter = TinyEmitter; + +export default Clipboard; diff --git a/package.json b/package.json index b56736d..e41c0b7 100644 --- a/package.json +++ b/package.json @@ -4,30 +4,29 @@ "description": "Modern copy to clipboard. No Flash. Just 2kb", "repository": "zenorocha/clipboard.js", "license": "MIT", - "main": "dist/clipboard.js", - "browser": "src/clipboard.js", - "browserify": { - "transform": [ - [ - "babelify", - { - "loose": "all" - } - ] - ] - }, + "main": "index.js", + "browser": "dist/clipboard.js", "keywords": [ "clipboard", "copy", "cut" ], "dependencies": { - "babelify": "^6.3.0", - "browserify": "^11.2.0", "delegate-events": "^1.1.1", "tiny-emitter": "^1.0.0" }, "devDependencies": { + "babel-core": "^5.8.23", + "babel-loader": "^5.3.2", + "babel-runtime": "^5.8.20", + "babelify": "^6.3.0", + "browser-sync": "^2.8.2", + "browserify": "^11.2.0", + "gulp": "^3.9.0", + "gulp-concat": "^2.6.0", + "gulp-rename": "^1.2.2", + "gulp-uglify": "^1.3.0", + "gulp-webpack": "^1.5.0", "karma": "^0.13.10", "karma-browserify": "^4.4.0", "karma-chai": "^0.1.0", @@ -37,15 +36,15 @@ "mocha": "^2.3.3", "phantomjs-polyfill": "0.0.1", "uglify": "^0.1.5", - "watchify": "^3.4.0" + "watchify": "^3.4.0", + "webpack": "^1.12.1" }, "scripts": { - "build": "npm run build-debug && npm run build-min", - "build-debug": "browserify src/clipboard.js -s Clipboard -o dist/clipboard.js", - "build-min": "uglify -s dist/clipboard.js -o dist/clipboard.min.js", - "build-watch": "watchify src/clipboard.js -s Clipboard -o dist/clipboard.js -v", - "test": "npm run test-browser && npm run test-server", - "test-browser": "karma start --single-run", - "test-server": "mocha test/module-systems.js" + "build-debug": "webpack", + "build": "gulp build", + "watch": "webpack --watch", + "test": "npm run build-debug && npm run test-browser && npm run test-server", + "test-browser": "npm run build-debug && karma start --single-run", + "test-server": "npm run build-debug && mocha test/module-systems.js" } } diff --git a/src/clipboard.js b/src/clipboard.js index f9930cf..1ac0f6d 100644 --- a/src/clipboard.js +++ b/src/clipboard.js @@ -6,7 +6,7 @@ import Emitter from 'tiny-emitter'; * Base class which takes a selector, delegates a click event to it, * and instantiates a new `ClipboardAction` on each click. */ -class Clipboard extends Emitter { +export default class Clipboard extends Emitter { /** * @param {String} selector * @param {Object} options @@ -119,5 +119,3 @@ function getAttributeValue(suffix, element) { return element.getAttribute(attribute); } - -export default Clipboard; diff --git a/test/module-systems.js b/test/module-systems.js index 1bff46c..db5ef14 100644 --- a/test/module-systems.js +++ b/test/module-systems.js @@ -3,7 +3,7 @@ var browserify = require('browserify'); describe('CommonJS', function() { it('should import the lib in a commonjs env without babel', function(done) { - browserify('./dist/clipboard.js').bundle(function(err) { + browserify('./index.js').bundle(function(err) { assert.equal(err, null); done(); }); diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 0000000..db32198 --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,18 @@ +var path = require('path'); + +module.exports = { + entry: path.resolve(path.join(__dirname, '.', 'index.js')), + output: { + path: path.resolve(path.join(__dirname, '.', 'dist')), + library: 'Clipboard', + libraryTarget: 'umd', + filename: 'clipboard.js' + }, + module: { + loaders: [{test: /\.js?$/, exclude: /(node_modules|bower_components)/, loader: 'babel?optional[]=runtime&stage=0'}] + }, + externals: [ + // delegate-events and tiny-emitter could go here if you want them externally provided + // {library: {root: 'LibraryWindowSymbol', amd: 'library', commonjs: 'library', commonjs2: 'library'}}, + ] +};