Commit 630eb142 by Marat Dreizin

Improved build flow and also added support of webpack/browserify

parent 07715d15
...@@ -15,77 +15,45 @@ module.exports = function(grunt) { ...@@ -15,77 +15,45 @@ module.exports = function(grunt) {
banner: "<%= banner %>" banner: "<%= banner %>"
}, },
dist: { dist: {
src: "<%= build.dist.dest %>", src: "<%= concat.dist.dest %>",
dest: "../raphael-min.js" dest: "../raphael-min.js"
} }
}, },
build: { replace: {
dist: {
options: { options: {
banner: "<%= banner %>" patterns: [{
match: "VERSION",
replacement: "<%= pkg.version %>"
}]
},
files: [{
expand: true,
flatten: true,
src: "<%= concat.dist.dest %>",
dest: "../"
}]
}
}, },
concat: {
dist: { dist: {
dest: "../raphael.js", dest: "../<%= pkg.name %>.js",
src: [ src: [
"../eve/eve.js", "../eve/eve.js",
"raphael.core.js", "raphael.core.js",
"raphael.svg.js", "raphael.svg.js",
"raphael.vml.js" "raphael.vml.js",
"raphael.amd.js"
] ]
} }
} }
}); });
// These plugins provide necessary tasks. // These plugins provide necessary tasks.
grunt.loadNpmTasks("grunt-contrib-concat");
grunt.loadNpmTasks("grunt-contrib-uglify"); grunt.loadNpmTasks("grunt-contrib-uglify");
grunt.loadNpmTasks("grunt-replace");
// Special concat/build task to handle Raphael's build requirements
grunt.registerMultiTask(
"build",
"Concatenate source, remove individual closures, embed version",
function() {
var data = this.data,
name = data.dest,
src = data.src,
options = this.options({
banner: ""
}),
// Start with banner
compiled = options.banner,
svgorvmlRegex = /\.(svg|vml)\.js/,
closureRegex = /window\.Raphael.*\(R\)\s*\{/,
closureEndRegex = /\}\(window\.Raphael\);\s*$/,
exposeRegex = /(\r?\n\s*\/\/\s*EXPOSE(?:\r|\n|.)*\}\)\);)/;
// Concatenate src
src.forEach(function(path) {
var source = grunt.file.read(path);
var match = svgorvmlRegex.exec(path);
// If either SVG or VML,
// remove the closure and add an early return if not required
if (match) {
source = "\n\n" +
source.replace(closureRegex,
"(function(){\n" +
" if (!R." + match[1] + ") {\n" +
" return;\n" +
" }"
)
.replace( closureEndRegex, "})();" );
// Add source before EXPOSE line
compiled = compiled.replace(exposeRegex, source + "$1");
} else {
compiled += source;
}
});
grunt.file.write( name, compiled );
grunt.log.ok("Built file " + name);
});
// Default task. // Default task.
grunt.registerTask("default", ["build", "uglify"]); grunt.registerTask("default", ["concat", "replace", "uglify"]);
}; };
require(['../raphael'], function(Raphael){ 'use strict';
require.config({
paths: {
raphael: '../raphael'
}
});
require(['raphael'], function(Raphael) {
var paper = Raphael(0, 0, 640, 720, "container"); var paper = Raphael(0, 0, 640, 720, "container");
// Work here
}); });
\ No newline at end of file
{ {
"name": "raphael", "name": "raphael",
"version": "2.1.2", "version": "2.1.3",
"description": "JavaScript Vector Library", "description": "JavaScript Vector Library",
"main": "raphael.js", "main": "raphael.js",
"scripts": { "scripts": {
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
"gitHead": "52bff469f60988f1391e8b3d7cb5349163df8ba1", "gitHead": "52bff469f60988f1391e8b3d7cb5349163df8ba1",
"devDependencies": { "devDependencies": {
"grunt": "~0.4.1", "grunt": "~0.4.1",
"grunt-contrib-uglify": "~0.2.0" "grunt-contrib-concat": "^0.5.0",
"grunt-contrib-uglify": "~0.2.0",
"grunt-replace": "^0.8.0"
} }
} }
// ┌────────────────────────────────────────────────────────────────────┐ \\
// │ Raphaël @VERSION - JavaScript Vector Library │ \\
// ├────────────────────────────────────────────────────────────────────┤ \\
// │ Copyright © 2008-2012 Dmitry Baranovskiy (http://raphaeljs.com) │ \\
// │ Copyright © 2008-2012 Sencha Labs (http://sencha.com) │ \\
// ├────────────────────────────────────────────────────────────────────┤ \\
// │ Licensed under the MIT (http://raphaeljs.com/license.html) license.│ \\
// └────────────────────────────────────────────────────────────────────┘ \\
(function (glob, factory) {
if (typeof define === "function" && define.amd) {
define("raphael", ["raphael.core", "raphael.svg", "raphael.vml"], function(Raphael) {
return (glob.Raphael = factory(Raphael));
});
} else if (typeof exports === "object") {
var raphael = require("raphael.core");
require("raphael.svg");
require("raphael.vml");
module.exports = factory(raphael);
} else {
glob.Raphael = factory(glob.Raphael);
}
}(window || this, function (Raphael) {
return Raphael.ninja();
}));
\ No newline at end of file
// ┌────────────────────────────────────────────────────────────────────┐ \\ // ┌────────────────────────────────────────────────────────────────────┐ \\
// │ "Raphaël 2.1.2" - JavaScript Vector Library │ \\ // │ Raphaël @@VERSION - JavaScript Vector Library │ \\
// ├────────────────────────────────────────────────────────────────────┤ \\ // ├────────────────────────────────────────────────────────────────────┤ \\
// │ Copyright (c) 2008-2011 Dmitry Baranovskiy (http://raphaeljs.com) │ \\ // │ Core Module │ \\
// │ Copyright (c) 2008-2011 Sencha Labs (http://sencha.com) │ \\ // ├────────────────────────────────────────────────────────────────────┤ \\
// │ Licensed under the MIT (http://raphaeljs.com/license.html) license. │ \\ // │ Licensed under the MIT (http://raphaeljs.com/license.html) license.│ \\
// └────────────────────────────────────────────────────────────────────┘ \\ // └────────────────────────────────────────────────────────────────────┘ \\
(function (glob, factory) { (function (glob, factory) {
// AMD support
if (typeof define === "function" && define.amd) { if (typeof define === "function" && define.amd) {
// Define as an anonymous module define("raphael.core", ["eve"], function(eve) {
define(["eve"], function( eve ) { return factory(eve);
return factory(glob, eve);
}); });
} else if (typeof exports === "object") {
module.exports = factory(require("eve"));
} else { } else {
// Browser globals (glob is window) glob.Raphael = factory(glob.eve);
// Raphael adds itself to window
factory(glob, glob.eve || (typeof require == "function" && require('eve')) );
} }
}(this, function (window, eve) { }(window || this, function (eve) {
/*\ /*\
* Raphael * Raphael
[ method ] [ method ]
...@@ -86,7 +84,7 @@ ...@@ -86,7 +84,7 @@
} }
} }
} }
R.version = "2.1.2"; R.version = "@@VERSION";
R.eve = eve; R.eve = eve;
var loaded, var loaded,
separator = /[, ]+/, separator = /[, ]+/,
...@@ -5371,13 +5369,5 @@ ...@@ -5371,13 +5369,5 @@
loaded = true; loaded = true;
}); });
// EXPOSE
// SVG and VML are appended just before the EXPOSE line
// Even with AMD, Raphael should be defined globally
oldRaphael.was ? (g.win.Raphael = R) : (Raphael = R);
if(typeof exports == "object"){
module.exports = R;
}
return R; return R;
})); }));
// ┌─────────────────────────────────────────────────────────────────────┐ \\ // ┌─────────────────────────────────────────────────────────────────────┐ \\
// │ Raphaël - JavaScript Vector Library │ \\ // │ Raphaël @@VERSION - JavaScript Vector Library │ \\
// ├─────────────────────────────────────────────────────────────────────┤ \\ // ├─────────────────────────────────────────────────────────────────────┤ \\
// │ SVG Module │ \\ // │ SVG Module │ \\
// ├─────────────────────────────────────────────────────────────────────┤ \\ // ├─────────────────────────────────────────────────────────────────────┤ \\
...@@ -8,7 +8,21 @@ ...@@ -8,7 +8,21 @@
// │ Licensed under the MIT (http://raphaeljs.com/license.html) license. │ \\ // │ Licensed under the MIT (http://raphaeljs.com/license.html) license. │ \\
// └─────────────────────────────────────────────────────────────────────┘ \\ // └─────────────────────────────────────────────────────────────────────┘ \\
window.Raphael && window.Raphael.svg && function(R) { (function (glob, factory) {
if (typeof define === "function" && define.amd) {
define("raphael.svg", ["raphael.core"], function(raphael) {
factory(raphael);
});
} else if (typeof exports === "object") {
factory(require("raphael.core"));
} else {
factory(glob.Raphael);
}
}(window || this, function(R) {
if (R && !R.svg) {
return;
}
var has = "hasOwnProperty", var has = "hasOwnProperty",
Str = String, Str = String,
toFloat = parseFloat, toFloat = parseFloat,
...@@ -1371,4 +1385,4 @@ window.Raphael && window.Raphael.svg && function(R) { ...@@ -1371,4 +1385,4 @@ window.Raphael && window.Raphael.svg && function(R) {
}; };
})(method); })(method);
} }
}(window.Raphael); }));
// ┌─────────────────────────────────────────────────────────────────────┐ \\ // ┌─────────────────────────────────────────────────────────────────────┐ \\
// │ Raphaël - JavaScript Vector Library │ \\ // │ Raphaël @@VERSION - JavaScript Vector Library │ \\
// ├─────────────────────────────────────────────────────────────────────┤ \\ // ├─────────────────────────────────────────────────────────────────────┤ \\
// │ VML Module │ \\ // │ VML Module │ \\
// ├─────────────────────────────────────────────────────────────────────┤ \\ // ├─────────────────────────────────────────────────────────────────────┤ \\
...@@ -8,7 +8,21 @@ ...@@ -8,7 +8,21 @@
// │ Licensed under the MIT (http://raphaeljs.com/license.html) license. │ \\ // │ Licensed under the MIT (http://raphaeljs.com/license.html) license. │ \\
// └─────────────────────────────────────────────────────────────────────┘ \\ // └─────────────────────────────────────────────────────────────────────┘ \\
window.Raphael && window.Raphael.vml && function(R) { (function (glob, factory) {
if (typeof define === "function" && define.amd) {
define("raphael.vml", ["raphael.core"], function(raphael) {
factory(raphael);
});
} else if (typeof exports === "object") {
factory(require("raphael"));
} else {
factory(glob.Raphael);
}
}(window || this, function(R) {
if (R && !R.vml) {
return;
}
var has = "hasOwnProperty", var has = "hasOwnProperty",
Str = String, Str = String,
toFloat = parseFloat, toFloat = parseFloat,
...@@ -973,4 +987,4 @@ window.Raphael && window.Raphael.vml && function(R) { ...@@ -973,4 +987,4 @@ window.Raphael && window.Raphael.vml && function(R) {
}; };
})(method); })(method);
} }
}(window.Raphael); }));
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
<script type="text/javascript" src="raphael.core.js"></script> <script type="text/javascript" src="raphael.core.js"></script>
<script type="text/javascript" src="raphael.svg.js"></script> <script type="text/javascript" src="raphael.svg.js"></script>
<script type="text/javascript" src="raphael.vml.js"></script> <script type="text/javascript" src="raphael.vml.js"></script>
<script type="text/javascript" src="raphael.amd.js"></script>
<script type="text/javascript"> <script type="text/javascript">
// Initialize container when document is loaded // Initialize container when document is loaded
......
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment