Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert to umd #15

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 65 additions & 54 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,65 +1,76 @@
var clone = require('clone');
var webpack = require('webpack');

module.exports = function (grunt) {

// Project configuration.
grunt.initConfig({
var config = {
pkg: grunt.file.readJSON('package.json'),
uglify: {
dist: {
options: {
banner: '/*' +
' * MIT Licensed' +
' * http://github.com/flowjs/fusty-flow.js' +
' * Aidas Klimas' +
' */',
compress: {
sequences: true, // join consecutive statemets with the “comma operator”
properties: true, // optimize property access: a["foo"] → a.foo
dead_code: true, // discard unreachable code
drop_debugger: true, // discard “debugger” statements
unsafe: false, // some unsafe optimizations (see below)
conditionals: true, // optimize if-s and conditional expressions
comparisons: true, // optimize comparisons
evaluate: true, // evaluate constant expressions
booleans: true, // optimize boolean expressions
loops: true, // optimize loops
unused: true, // drop unused variables/functions
hoist_funs: true, // hoist function declarations
hoist_vars: false, // hoist variable declarations
if_return: true, // optimize if-s followed by return/continue
join_vars: true, // join var declarations
cascade: true, // try to cascade `right` into `left` in sequences
side_effects: true, // drop side-effect-free statements
warnings: true, // warn about potentially dangerous optimizations/code
global_defs: {} // global definitions
}
},
files: {
'build/fusty-flow.min.js': [
'bower_components/flow.js/src/flow.js',
'src/fusty-flow-factory.js',
'src/fusty-flow.js'
]
}
}
},
concat: {
flow: {
files: {
'build/fusty-flow.js': [
'bower_components/flow.js/src/flow.js',
'src/fusty-flow-factory.js',
'src/fusty-flow.js'
]
}
webpack: {
standalone: clone(require('./webpack.base.config')),
lib: clone(require('./webpack.base.config')),
libMin: clone(require('./webpack.base.config'))
}
};

//////////////////////////////////////
// Standalone webpack overrides
//////////////////////////////////////
config.webpack.standalone.output.filename = 'dist/fusty-flow-standalone.js';

//////////////////////////////////////
// Library webpack overrides
//////////////////////////////////////
config.webpack.lib.output.filename = 'dist/fusty-flow.js';

config.webpack.lib.externals = [
{
'flow.js': {
'commonjs': 'flow.js',
'commonjs2': 'flow.js',
'amd': 'flow',
'root': 'Flow'
}
}
});
];

/////////////////////////////////////
//Minified library overrides
/////////////////////////////////////
config.webpack.libMin.output.filename = 'dist/fusty-flow.min.js';

config.webpack.libMin.externals = config.webpack.lib.externals;

config.webpack.libMin.plugins.push(new webpack.optimize.UglifyJsPlugin({
compress: {
sequences: true, // join consecutive statemets with the “comma operator”
properties: true, // optimize property access: a["foo"] → a.foo
dead_code: true, // discard unreachable code
drop_debugger: true, // discard “debugger” statements
unsafe: false, // some unsafe optimizations (see below)
conditionals: true, // optimize if-s and conditional expressions
comparisons: true, // optimize comparisons
evaluate: true, // evaluate constant expressions
booleans: true, // optimize boolean expressions
loops: true, // optimize loops
unused: true, // drop unused variables/functions
hoist_funs: true, // hoist function declarations
hoist_vars: false, // hoist variable declarations
if_return: true, // optimize if-s followed by return/continue
join_vars: true, // join var declarations
cascade: true, // try to cascade `right` into `left` in sequences
side_effects: true, // drop side-effect-free statements
warnings: true, // warn about potentially dangerous optimizations/code
global_defs: {} // global definitions
}
}));

grunt.initConfig(config);

// Load the plugin that provides the "uglify" task.
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-webpack');

// Default task(s).
grunt.registerTask('build', ['uglify', 'concat']);
grunt.registerTask('default', ['build']);

grunt.registerTask('build', ['webpack']);
};
3 changes: 1 addition & 2 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"name": "fusty-flow.js",
"version": "1.2.0",
"main": [
"src/fusty-flow.js",
"src/fusty-flow-factory.js"
"dist/fusty-flow.js"
],
"ignore": [
"**/.*",
Expand Down
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "fusty-flow.js",
"version": "1.2.0",
"description": "Flow.js html5 file upload support for older browsers based on iframe upload.",
"main": "src/fusty-flow-factory.js",
"main": "dist/fusty-flow.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand All @@ -22,8 +22,14 @@
"license": "MIT",
"readmeFilename": "README.md",
"devDependencies": {
"babel-polyfill": "^6.3.14",
"clone": "^1.0.2",
"grunt": "~0.4.1",
"grunt-contrib-uglify": "~0.11.0",
"grunt-contrib-concat": "~0.5.1"
"grunt-webpack": "^1.0.11",
"webpack": "^1.12.11",
"webpack-dev-server": "^1.14.1"
},
"dependencies": {
"flow.js": "git@github.com:flowjs/flow.js.git#v2.9.0"
}
}
5 changes: 2 additions & 3 deletions samples/frontend.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
<html>
<head>
<title></title>
<script src="../bower_components/flow.js/src/flow.js"></script>
<script src="../src/fusty-flow-factory.js"></script>
<script src="../src/fusty-flow.js"></script>
<script src="../bower_components/flow.js/dist/flow.js"></script>
<script src="../dist/fusty-flow.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<style>
.list {
Expand Down
20 changes: 9 additions & 11 deletions src/fusty-flow-factory.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
(function (Flow, FustyFlow, window) {
'use strict';
var Flow = require('flow.js');
var FustyFlow = require('./fusty-flow');

var fustyFlowFactory = function (opts) {
var flow = new Flow(opts);
if (flow.support) {
return flow;
}
return new FustyFlow(opts);
var fustyFlowFactory = function (opts) {
var flow = new Flow(opts);
if (flow.support) {
return flow;
}
return new FustyFlow(opts);
}

window.fustyFlowFactory = fustyFlowFactory;

})(window.Flow, window.FustyFlow, window);
module.exports = fustyFlowFactory;
Loading