Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to make Zepto compatible with Browserify?
    primarykey
    data
    text
    <p>I made some changes to Zepto and hope I can use it in Browserify:</p> <pre><code>➤➤ 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" &amp;&amp; module &amp;&amp; typeof module.exports === "object" ) { + module.exports = Zepto; +} else { + if ( typeof define === "function" &amp;&amp; define.amd ) { + define( "zepto", [], function () { return Zepto; } ); + } +} +if ( typeof window === "object" &amp;&amp; typeof window.document === "object" ) { + window.Zepto = Zepto + // If `$` is not yet defined, point it to `Zepto` + '$' in window || (window.$ = Zepto) +} </code></pre> <p>But I got errors:</p> <pre><code>/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) </code></pre> <p>Is there any solution?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload