I should mention, you don't have to use tedit, I'm just giving that as an example. My point is it doesn't take much to have a node-style require in the browser, especially if you're willing to use a transform step. Browserify is very good at this and is quite full featured. I think there may be a way to configure it to not need as much boilerplate, but I'm not sure.
For my personal needs, browserify was not an option and what I developed for tedit has worked very nicely for me. On Fri, Mar 7, 2014 at 12:05 PM, Tim Caswell <t...@creationix.com> wrote: > Yes, if you just want the node style require system in the browser and are > willing to use a transform step, it's pretty easy. I'm doing this for my > tedit project. > > I have two build styles that I use. One wraps all the source code in amd > style wrappers and then uses a tiny bootstrap program to dynamically inject > the script tags. The other style scans a file for requires and grabs all > it's dependencies and outputs a single concatenated file (much like > browserify does). This also works with a tiny require system. > > Here is the bootstrap that tedit uses. > https://github.com/creationix/tedit-app/blob/master/chrome-app/bootstrap.js. > It's designed to inject script tags on demand. If you go the other route > and combine all dependencies into a single file, then most of this file can > even go away. > > Tedit has a declarative build system baked in and doesn't use grunt or > anything like that because I need to run in environments where there is no > node or command-line. The build tool that compiles a tree of node-style > modules and emits a tree of amd wrapped modules is > https://github.com/creationix/my-filters/blob/master/amd-tree.js > > --Tim Caswell > > > > > On Fri, Mar 7, 2014 at 1:04 AM, Simeon Chaos <simeon.ch...@gmail.com>wrote: > >> Sorry for the typo: "browserify will add at least minified 150 bytes" >> --> should be "about 350 bytes after minified" >> >> 在 2014年3月7日星期五UTC+8下午2时56分43秒,Simeon Chaos写道: >> >>> Do you need packages and modules in browser? >>> With require.js you can "define" and "require" something (AmdJS spec) in >>> 15kb. Need run node.js in browser? r.js implement it in 1007kb based on >>> require.js. >>> With browserify you can "exports" and "require" like in node.js(CommonJS >>> spec), but browserify will add at least minified 150 bytes for your every >>> file, and browserify is a nodejs packages itself, and It has about 1000+ >>> lines(index.js:750 lines, bin/cmd.js: 75 lines, bin/args.js: 233 lines). >>> Is it possible to make node.js module run in browser by 1 kb javascript >>> code? >>> Yes. With twoside.js, we can have the basic features of browserify and >>> some other flexibilities by 1kb. >>> After adding twoside.js(100 lines, 1000 bytes) with <script> tag, you >>> can use package and modules like in modules, by wrapping module with one >>> line(120 bytes). and with gulp-twoside.js(75 lines) you can wrap the >>> modules automatically and get some other features. >>> 1kb can make it. >>> To get twoside.js, please "npm install twoside", or go to >>> https://github.com/chaosim/twoside >>> >>> >> -- >> -- >> Job Board: http://jobs.nodejs.org/ >> Posting guidelines: >> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines >> You received this message because you are subscribed to the Google >> Groups "nodejs" group. >> To post to this group, send email to nodejs@googlegroups.com >> To unsubscribe from this group, send email to >> nodejs+unsubscr...@googlegroups.com >> For more options, visit this group at >> http://groups.google.com/group/nodejs?hl=en?hl=en >> >> --- >> You received this message because you are subscribed to the Google Groups >> "nodejs" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to nodejs+unsubscr...@googlegroups.com. >> For more options, visit https://groups.google.com/d/optout. >> > > -- -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to nodejs@googlegroups.com To unsubscribe from this group, send email to nodejs+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.