GithubHelp home page GithubHelp logo

requirejs / cajon Goto Github PK

View Code? Open in Web Editor NEW
117.0 117.0 11.0 2.31 MB

JavaScript module loader for the browser that can load CommonJS/node and AMD modules

License: Other

JavaScript 96.51% HTML 3.47% Shell 0.02%

cajon's Introduction

RequireJS

RequireJS loads plain JavaScript files as well as more defined modules. It is optimized for in-browser use, including in a Web Worker, but it can be used in other JavaScript environments, like Rhino and Node. It implements the Asynchronous Module API.

RequireJS uses plain script tags to load modules/files, so it should allow for easy debugging. It can be used simply to load existing JavaScript files, so you can add it to your existing project without having to re-write your JavaScript files.

RequireJS includes an optimization tool you can run as part of your packaging steps for deploying your code. The optimization tool can combine and minify your JavaScript files to allow for better performance.

If the JavaScript file defines a JavaScript module via define(), then there are other benefits RequireJS can offer: improvements over traditional CommonJS modules and loading multiple versions of a module in a page. RequireJS also has a plugin system that supports features like i18n string bundles, and text file dependencies.

RequireJS does not have any dependencies on a JavaScript framework.

RequireJS works in IE 6+, Firefox 2+, Safari 3.2+, Chrome 3+, and Opera 10+.

Latest Release

License

MIT

Code of Conduct

jQuery Foundation Code of Conduct.

Directories

  • dist: Scripts and assets to generate the requirejs.org docs, and for generating a require.js release.
  • docs: The raw HTML files for the requirejs.org docs. Only includes the body of each page. Files in dist are used to generate a complete HTML page.
  • tests: Tests for require.js.
  • testBaseUrl.js: A file used in the tests inside tests. Purposely placed outside the tests directory for testing paths that go outside a baseUrl.
  • updatesubs.sh: Updates projects that depend on require.js Assumes the projects are siblings to this directory and have specific names. Useful to copy require.js to dependent projects easily while in development.

Tests

This repo assumes some other repos are checked out as siblings to this repo:

git clone https://github.com/requirejs/text.git
git clone https://github.com/requirejs/i18n.git
git clone https://github.com/requirejs/domReady.git
git clone https://github.com/requirejs/requirejs.git

So when the above clones are done, the directory structure should look like:

  • domReady
  • i18n
  • text
  • requirejs (this repo)

You will need to be connected to the internet because the JSONP and remoteUrls tests access the internet to complete their tests.

Serve the directory with these 4 siblings from a web server. It can be a local web server.

Open requirejs/tests/index.html in all the browsers, click the arrow button to run all the tests.

cajon's People

Contributors

jrburke avatar kirill-konshin avatar yortus avatar ysangkok 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

cajon's Issues

Conditional comments around sourceUrl comment causing grey hair

Is there any chance Cajon would switch over to the //# sourceUrl= style of notation?

The conditional comments around the line which appends the magical //@ sourceURL= have a nasty habit of being stripped when passed through UglifyJS.

I attempted to solve the issue by rolling my own function for determining which comments to keep, but alas, the /*@end@*/ comment is ignored, apparently because there's no code following it in the block. If I add an executable line below the closing comment, it's passed into the preserve comment function for evaluation.

I do realise, that I should probably just change our development build to skip Cajon in the uglification process and just keep it as is, but I strive to having the build as similar as possible to minimise variables between environments.

Remove Query from path in debugger...

Any way to decrease the length of the file name as displayed in the Chrome debugger by removing the query string parameters from the file path?

Convert this:

http://localhost:5000/gherkin-runner/gherkinRunner.html?featurePaths=features/stepArgumentTypes&libraryPaths=features/step_definitions/../gherkin-runner/scripts/text.js

To this:

http://localhost:5000/gherkin-runner/scripts/text.js

not working with text plugin

var template = require('text!tmpl/something.tmpl')
// Uncaught Error: Module name "text!tmpl/simple.tmpl_unnormalized2" has not been loaded yet for context: _
var template = require(['text!tmpl/something.tmpl'], function (template) {
  // no problem
})

"exports is not defined"

Hi, I'm trying to use cajon with some existing CJS modules that use this exports pattern:

function Example(name) {
    this.name = name;
}
exports.Example = Example;

However this doesn't seem to work with Cajon, console shows error:
"exports is not defined"

However, this pattern does:

function Example(name) {
    this.name = name;
}
module.exports = {
    Example: Example
}

Is this on purpose and/or expected? I have a lot of code that I'd rather not convert (which is why I'd like to use cajon here).

Not working with handlebars via the requirejs-handlebars plugin?

Everything worked fine pre-cajon. Upon switching to cajon, handlebars (1.0.0, installed from bower, shimmed, used via the requirejs-handlebars plugin) is failing with this error:

Uncaught TypeError: Cannot call method 'compile' of undefined in /components/requirejs-handlebars/hb.js:15

This is the exact same error I'd see if I forgot to shim handlebars normally (ie. without cajon).

If I wrap handlebars.js with define([], function() { /*handlebars code*/ return Handlebars; }); or comment out the handlebars shim in requirejs.config and add module.exports = Handlebars; to the end of handlebars.js it works fine.

But with no modifications to handlebars.js, shim or not, I see that error. It's as if the handlebars shim config is being ignored.

Cajon is not available via Bower

Please make it available via Bower. Currently I have to refer to it in bower.json in a following ugly way:

"cajon": "https://raw.githubusercontent.com/requirejs/cajon/master/cajon.js",

Backbone shim

Hi,

I had a config with Backbone shim working just fine with regular requirejs. Wanted to move over to use Cajon to reuse models in Node.js. It' seems however that shimming Backbone with the exact same config doesn't work:

paths: {
jquery: 'vendor/jquery',
underscore: 'vendor/underscore',
backbone: 'vendor/backbone',
...
},

shim: {
jquery: {
exports: 'jQuery'
},

underscore: {
  exports: '_'
},

backbone: {
  deps: ['underscore', 'jquery'],
  exports: 'Backbone'
},

When backbone is initialized there is not jQuery available, any idea why this would be?

Support require([js-data-uri]);

In this pull, base64 javascript url support was added for the paths config.
#845 . It also enables this snippet

var url = 'data:text/javascript,define([], function() { return "wut" })';
require([url], function (wut) {
    wut === 'wut'
});

See this example working with Require.js
http://jsfiddle.net/qsRT8/

I can't find cajon on any public CDN, but if you run the same thing with cajon it will fail because it is trying to do an XHR (because cajon) to the data uri, but that get's blocked by the browser because of Same-Origin Policy ('data:' is different protocol and thus different origin).

I am making a component loader that will support specifying a URL to JavaScript to run the component. The component may have a bundle that does all the right things at an http url, but it may just want to execute a bit of JavaScript without entailing the HTTP Request or having to host a file.

Could Cajon do a script tag load in the case that the URL is a data uri?

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.