Coder Social home page Coder Social logo

require's Introduction

require brings require to the browser

Node's require() is the de facto javascript dependency statement.

npm is the de facto javascript module manager.

require brings both of them to the browser.

tl;dr

"Just give me some code that runs"

mkdir app; cd app
echo '{ "name":"app" }' > package.json
sudo npm install require
sudo npm install raphael
curl -O https://raw.github.com/gist/975866/little_server.js
curl -O https://raw.github.com/gist/975868/little_client.js
node little_server.js

Now go to http://localhost:8080

Install

sudo npm install -g require

Run

Start dev server""

require serve ./example --port 1234 --host localhost

In your HTML:

<script src="//localhost:1234/require/client"></script>

This is like calling require('client') from inside ./example. Read more on node's require path resolution

Compile

(You'll want to do this before you deploy to production)

require compile ./example/client.js > client.min.js

Use programmatically

In your node js:

require('require/server').listen(1234, __dirname + '/example')

or mount it on an http server you're already running

var server = http.createServer(function(req, res) { })
require('require/server').mount(server)
server.listen(8080, 'localhost')

or, as connect middleware

connect.createServer(
	connect.static(__dirname + '/example'),
	require('require/server').connect(__dirname + '/example')
)

Compile programmatically:

var compiler = require('require/compiler')
console.log(compiler.compile('./example/client.js'))
console.log(compiler.compileCode('require("./example/client")'))

The compiler supports all the options of https://github.com/mishoo/UglifyJS, e.g.

compiler.compile('./example/client.js', { beautify:true, ascii_only:true })

require's People

Contributors

marcuswestin avatar rektide avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

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.