This setup demonstrates the use of the 'empty:' path value on a r.js build profile
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
README.md
app.js
build.js
external_config.js
index.html
main-built.js
main.js
require.config.js
require.js

README.md

RequireJS Sample App

see master branch for a working example

Tests r.js build profile options:

-> paths: { 'moduleName': 'external_path' } + 'empty:' ( branch:empty )

// require.config.js
require.config({
    paths: {
        'moduleName': 'http://example.com/moduleName'
    }
})

// build.js
({
    paths: {
        'moduleName': 'empty:'
    },
    mainConfigFile: 'require.config.js'
})

Module path doesn't resolve properly because relevant path map in require.config.js isn't included in output file.

workaround

  1. require.config() must be in the same file as main module
  2. force inclusion with include directive: include: [ 'require.config' ]

-> wrap: true + paths.moduleName: 'empty:' ( branch:wrap )

// build.js
({
    paths: {
        'moduleName': 'empty:'
    },
    wrap: true
})

Results in define() is undefined. RequireJS does try to load the external module but is executed in the window context (I think).

workaround

  1. don't use wrap: true

-> name: 'require' doesn't include ./require.js in built file ( branch:path )

// build.js
({
    name: 'require'
})

fails silently, does check for the presence of the ./require.js module but doesn't include it in the output file. ( maybe it needs a warning because require is a reserved module name right? )

'require.js', ../<current_dir>/require both resolve properly and include ./require.js

workaround

  1. specify extension, place require.js on a subfolder or url