A command line tool for running JavaScript scripts that use the Asychronous Module Defintion API (AMD) for declaring and using JavaScript modules and regular JavaScript script files. It is part of the RequireJS project, and works with the RequireJS implementation of AMD.
Questions tagged [r.js]
287 questions
66
votes
2 answers
Dynamic require in RequireJS, getting "Module name has not been loaded yet for context" error?
Is there a way to define a module that "dynamically" load other modules in RequireJS? If yes, how the optimizer (r.js) understands how/when a module has to be included?
For example, let dynModules a module which defines name/path pairs:
define([],…

gremo
- 47,186
- 75
- 257
- 421
34
votes
5 answers
Most Efficient Multipage RequireJS and Almond setup
I have multiple pages on a site using RequireJS, and most pages have unique functionality. All of them share a host of common modules (jQuery, Backbone, and more); all of them have their own unique modules, as well. I'm wondering what is the best…

davidtheclark
- 4,666
- 6
- 32
- 42
19
votes
1 answer
Disable uglyfying in r.js
I am looking for a way to prevent r.js (RequireJS' optimization script) from ugylyfying our JS-modules to maintain readability for debugging purposes.
I expect the script (running on Node.js by the way) to have some command line option to be…

Leo Selig
- 1,062
- 1
- 16
- 30
11
votes
2 answers
Using r.js to package a SPA application that loads views using 'text'
I'm attempting to build a SPA application (requirejs, durandal 2, knockout) into a single main-build.js file using grunt, and I'm running into serious issues with the 'text' plugin that durandal is using to load my views.
In dev, I'm successfully…

Kieran Benton
- 8,739
- 12
- 53
- 77
10
votes
4 answers
parse error using esprima for file while optimizing js files with r.js
I am optimizing several js files into one using r.js. It works fine before. Recently,I modified some js code, add the code as:
var x = 08;
then it shows
ERROR:parse error using esprima for file D://webroot/js/a.js
ERROR:line 45: Unexpected token…

florence
- 101
- 1
- 1
- 3
9
votes
1 answer
Avoid duplication of "paths" configuration in RequireJS main file and r.js build file?
Here is (part of) my folder structure:
node-test
bower_components
build
public
main.js
build.js
Running the optimizer with r.js -o build.js and the following configuration works fine:
// main.js file
requirejs.config({
baseUrl:…

gremo
- 47,186
- 75
- 257
- 421
8
votes
4 answers
How do I use Backbone.js with Require.js (r.js), but resulting in 2 files after I optimize it?
I have followed the basic tutorials (results in one file after you run r.js)
The problem is, my main.js file at the end is 500KB. That's too big. I want to split it into two files.
I want to optimize my main.js file into two files:
One that holds…

TIMEX
- 259,804
- 351
- 777
- 1,080
8
votes
1 answer
How Can I Place RequireJS Config in Separate File and Make the r.js Optimizer Work?
Most examples for RequireJS setup, place the configuration object in the main.js entry point, something like this:
//main.js
require.config({
"paths": {
//libs
"lib1": "assets/js/lib/lib1",
"lib2": "assets/js/lib/lib2",
"lib3":…

elanh
- 1,401
- 3
- 19
- 31
8
votes
1 answer
Using grunt requirejs with almond results in "define is not defined"
In my grunt.js file I've got
requirejs: {
dist: {
options: {
almond: true,
wrap: true,
modules: [{name: 'main'}],
mainConfigFile: "src/js/main.js",
baseUrl: "src/js",
…

Peter
- 946
- 9
- 23
6
votes
1 answer
How can I use a local file during Require.js optimisation, but a CDN-hosted version at runtime?
My page includes several components that exist as separate AMD modules. Each of these components is turned into a single file by the Require.js optimiser. Because several of these components share dependencies (e.g. jQuery and d3), the optimiser…

Rich Harris
- 28,091
- 3
- 84
- 99
6
votes
3 answers
How to exclude urlArgs from build using r.js
I use r.js optimizer to combine js files based on build profile as it's suggested in documentation. Here's my build-config.js:
({
baseUrl: ".",
paths: {
jquery: '//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min',
},
…

Dmitry
- 1,484
- 2
- 15
- 23
5
votes
2 answers
Using requirejs optimizer node module with Gulp
There's gulp-requirejs plugin, but it's blacklisted with the following message: "use the require.js module directly".
The docs are quite sparse, how would I best use it in conjunction with Gulp build task?
In the docs there's an example:
var…

any_h
- 530
- 3
- 10
- 27
5
votes
0 answers
Play Framework requirejs Error: Error: paths fallback not supported in optimizer
I use Play 2.3.7 and get the following error:
[info] Error: Error: paths fallback not supported in optimizer. Please provide a build config path override for jsparticipantroutes
It appears just on prod mode with ./activator start. In dev mode…

Whatever
- 115
- 1
- 2
- 7
5
votes
1 answer
What does r.js really do?
I'm trying to understand the benefits of the popular r.js.
It seems to...
concatenate a list of manually selected JavaScript files
uglify/minimize that combined code
do some similar stuff for CSS files (combine them)
Also, (what it makes it…

Udo G
- 12,572
- 13
- 56
- 89
5
votes
1 answer
Grunt build not exposing the globals I need
When I run my project locally with my grunt:server task, the project works as I expect. However, after building which takes all the vendor code and puts it into one file, two of my needed module aren't avialable, and the project doesn't work.
Here…

elsherbini
- 1,596
- 13
- 23