我对 Zepto 进行了一些更改,希望可以在 Browserify 中使用它:
➤➤ git diff
diff --git a/package.json b/package.json
index 294af90..e4f8fd1 100644
--- a/package.json
+++ b/package.json
@@ -7,6 +7,7 @@
, "dist": "coffee make dist"
, "start": "coffee test/server.coffee"
}
+ , "main": "dist/zepto.js"
, "repository": {
"type": "git"
, "url": "https://github.com/madrobby/zepto.git"
diff --git a/src/zepto.js b/src/zepto.js
index 93bfe18..cdf8929 100644
--- a/src/zepto.js
+++ b/src/zepto.js
@@ -787,6 +787,17 @@ var Zepto = (function() {
return $
})()
-// If `$` is not yet defined, point it to `Zepto`
-window.Zepto = Zepto
-'$' in window || (window.$ = Zepto)
+// detect module loader like jQuery
+// http://code.jquery.com/jquery-2.0.3.js
+if ( typeof module === "object" && module && typeof module.exports === "object" ) {
+ module.exports = Zepto;
+} else {
+ if ( typeof define === "function" && define.amd ) {
+ define( "zepto", [], function () { return Zepto; } );
+ }
+}
+if ( typeof window === "object" && typeof window.document === "object" ) {
+ window.Zepto = Zepto
+ // If `$` is not yet defined, point it to `Zepto`
+ '$' in window || (window.$ = Zepto)
+}
但我得到了错误:
/usr/lib/node_modules/watchify/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/lib/async.js:91
var dir = path.resolve(x, pkg.main);
^
TypeError: Cannot read property 'main' of undefined
at /usr/lib/node_modules/watchify/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/lib/async.js:91:54
at load (/usr/lib/node_modules/watchify/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/lib/async.js:54:43)
at /usr/lib/node_modules/watchify/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/lib/async.js:60:22
at /usr/lib/node_modules/watchify/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/lib/async.js:16:47
at Object.oncomplete (fs.js:107:15)
有什么解决办法吗?