Coder Social home page Coder Social logo

browserbuild's Introduction

This repository is no longer maintained

Browserbuild

Browserbuild allows you to write code for the browser that leverages require, module and exports, but that gets exposed as a global.

It doesn't enforce any script loaders on the user to leverage the compiled library.

Example

  1. Write for Node

    lib/hithere.js

    var b = require('./b')
    
    module.exports = function () {
      alert('hello ' + b());
    }

    lib/b.js

    module.exports = function () {
      return 'world';
    }
    
  2. Build for browser!

    $ browserbuild -m hithere -b lib/ `find lib -name '*.js'` > my-library.js
  3. Use!

    <script src="my-library.js"></script>
    <script>
      hithere();
    </script>

Features

  • Write code like you would write for Node.JS.
    • No wrappers
    • No undefined type checking for module or window.
  • No new patterns
    • No AMD, no require.async, no CommonJS transport proposals.
    • Doesn't depend on require implementations on the client.
    • It exposes your module as a single global, like jQuery, io, _. Just like everyone is used to.
  • No code bloat.
    • The conversion for the browser only adds a few lines of code.
    • No trouble debugging.
  • debug integration
    • Make dev builds with debugging enabled.

Credits

License

(The MIT License)

Copyright (c) 2011 Guillermo Rauch <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

browserbuild's People

Contributors

belcherj avatar ericgj avatar fnogatz avatar mixu avatar rauchg avatar retrofox avatar slaskis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

browserbuild's Issues

Error: process.stdout cannot be closed

Is there something wrong with my setup? Just a minor inconvenience with browserbuild 0.1.0 from npm, on node v0.6.4:

$ ./bin/browserbuild

  Usage: browserbuild [options]

  Options:

    -h, --help             output usage information
    -V, --version          output the version number
    -g, --global <name>    Name of the global to export [browserbuild]
    -f, --filename <name>  Name of the file to create [browserbuild.js]
    -m, --main <name>      Name of the main module to export (auto)
    -s, --skip-parse       Avoid parsing meta-blocks


  Examples:

    $ browserbuild dir/
    $ browserbuild -g test file.js


node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
Error: process.stdout cannot be closed
    at WriteStream.<anonymous> (node.js:284:15)
    at Command.<anonymous> (/home/user/browserbuild-test/node_modules/browserbuild/node_modules/commander/lib/commander.js:922:18)
    at Command.emit (events.js:88:20)
    at Object.<anonymous> (/home/user/browserbuild-test/node_modules/browserbuild/bin/browserbuild:38:11)
    at Module._compile (module.js:432:26)
    at Object..js (module.js:450:10)
    at Module.load (module.js:351:31)
    at Function._load (module.js:310:12)
    at Array.0 (module.js:470:10)
    at EventEmitter._tickCallback (node.js:192:40)

Same error happens with ./bin/browserbuild -h but not with ./bin/browserbuild -V.

And if the file is not found, node throws Error: ENOENT, no such file or directory. Perhaps there is a nicer way.

nice library

hey - nice lib --- this isn't an issue - just giving feedback, feel free to delete.

If you're going to have a credits section - I wouldn't mind being credited for the original require functions - TJ did a light refactor ^_^

Extensions for Collaboration with bower

Hi,

currently we are looking into using bower instead of ender in our client side javascript projects. We are therefore evaluating different alternatives to replace the require/provide glue code generated by ender. Browserbuild appeals to us mostly because of its light weight approach and low complexity while more or less providing the same api our code base already uses.

However, some small additions might be required to make the transition as smooth as possible. I'd like to check with you, whether these features are something you would like to see in browserbuild. If so, I'll consider preparing a pull request.

The way I imagine browserbuild to be used in conjunction with bower is to leverage bower´s list --paths feature. Basically, it allows to determine a hash of main source files indexed by package names. Inside our code we would like to require libraries by these package name. It would therefore be necessary to register dependent library files by a specified name rather then by their exact file name. For example we would like to call require('mylib') instead of require('components/mylib/dist/mylib.js'). I could imagine a grunt plugin combining the strengths of bower and browserbuild, if the browserbuild api allowed files to be registered by explicitly given names.

I want to emphasize again, that it is not my plan to make browserbuild depend on bower in any way. But with this simple addition, the two could be used together while keeping their UNIX-philosophy style focus.

Best
Tim

Error: Cannot find module '../package' when run on heroku

~ $ node --version
v0.4.7
~ $ cat node_modules/browserbuild/package.json | grep '"version"'
  "version": "0.6.0",
Running bash attached to terminal... up, run.1580
~ $ browserbuild 

node.js:134
        throw e; // process.nextTick error, or 'error' event on first tick
        ^
Error: Cannot find module '../package'
    at Function._resolveFilename (module.js:320:11)
    at Function._load (module.js:266:25)
    at require (module.js:348:19)
    at Object.<anonymous> (/app/node_modules/browserbuild/bin/browserbuild:11:12)
    at Module._compile (module.js:404:26)
    at Object..js (module.js:410:10)
    at Module.load (module.js:336:31)
    at Function._load (module.js:297:12)
    at Array.<anonymous> (module.js:423:10)
    at EventEmitter._tickCallback (node.js:126:26)

Example won't build in Windows

The example in the README won't build properly from the Windows cmd.exe command line (I'm running Windows 7 x64). The error is:

error: option -m, --main <name>' argument missing, got-e'

which suggest some kind of command line parsing error.

The example works fine from a bash shell.

-Steve

Require JSON

Currently it's not possible to use browserbuild once a simple JSON file gets required. Sometimes I use

var obj = require('./something.json');

Browserbuild expects exports or module.exports but unfortunately no JSON file.

Support for global object

Hi there,

I think it would be handy to translate node's global object into browser`s window object.

What do you think?

Generate static, standalone file?

I've been perusing the code, and my conclusion is that you can't use browserbuild to generate a single, static file that you can just plop down on a page without any other dependencies. Is that right?

For example, say I only have an HTML file with a <script> tag including the built file. No node.js web server or anything. Will that work?

async ?

ever considered an async version that uses ajax to fetch and then wrap, before going through and finding 'require' dependencies?

I've got it working really well in brequire, and find it's really useful to be able to avoid maintaining a manifest file of packages during development.

relative paths question

Apologies to ask this support question here, but I didn't see anywhere else to ask. I cannot get browserbuild to work as described in the README. I am sure it's something basic I'm missing.

If I have files b.js and hithere.js as described in the README (all, including the main, in a lib directory), and run browserbuild as described, the output I get looks like this:

// require functions wrapper
require.register("lib/b.js", function(module, exports, require, global){ ... });
require.register("lib/hithere.js", function(module, exports, require, global){ ... });
var exp = require('hithere');if ("undefined" != typeof module) module.exports = exp;else hithere = exp;

And I get an error trying to require('hithere'), since it was registered as 'lib/hithere.js'.

I thought perhaps the base path needed to be provided, e.g. browserbuild -m hithere -b lib ..., but that doesn't work either as it registers it as '/hithere.js' .

The only way I could get it to work is to run within the source dir, e.g. cd lib && browserbuild -m hithere ... .

What am I missing? Thanks in advance.

Eric

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.