Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Require.js not compiling single js file correctly

Tags:

requirejs

I'm trying to build my require.js modules to one javascript file for production.

The command I'm running is...

r.js -o name=main out=main.min.js mainConfigFile=main.js

This compiles but the compiled main.min.js file is not compiled correctly and still includes the "define" statement blocks. and the browser obviously returns

Uncaught ReferenceError: define is not defined 

My main.js file looks like:

require.config({
    paths: {
        jquery: 'libs/jquery/jquery',
    },
    shim: {
        bootstrap: {
            deps: ['jquery'],
            exports: 'jquery'
        }
    }
});
require(['app', 'jquery'], function (app, $) {
    'use strict';
    // use app here
    console.log(app);
    console.log('Running jQuery %s', $().jquery);
});

Please let me know what I'm overlooking here. Thanks!

like image 983
markstewie Avatar asked Mar 07 '13 03:03

markstewie


1 Answers

You're correct, you need to include requireJS in your build. Take a look at http://requirejs.org/docs/optimization.html#onejs. You'll find an example for the command line there. If you're using a build profile it will look something like this -

({
baseUrl: "../Scripts",
paths: {
    requireLib: 'libs/require'
},
name: "main",
out: "main-built.js",
include: ["requireLib"]
})
like image 66
JackMorrissey Avatar answered Sep 19 '22 15:09

JackMorrissey