How can I get requirejs modules to compile as expected?


November 2018


65 time


Below is an experimental build.js file I am creating to test compiling a multi-module application with require.js. When I run the following it builds, but the resulting ./scripts/main.js does not have require.js inlined into it as would be expected.

If I remove the 2nd module definition, it will then compile as expected. I've read the docs and looked Burke's multi-page example here -> all to no avail. I have tried various permutations of the include/exclude settings all to no avail.

Any pointers on what I may be doing wrong would be appreciated.

var requirejs = require('requirejs');

var config = {
    appDir: './app',
    baseUrl: './',
    paths: {
        requireLib: './scripts/require'
    optimize: false,
    modules: [
            name: './scripts/main',
            include: ['requireLib']
            name: './scripts/moduleA/main',
            include: ['./scripts/moduleA/main'],
            exclude: ['./scripts/main',
    dir: 'app-debug'

requirejs.optimize(config, function(buildResponse) {
    var contents = fs.readFileSync(config.out, 'utf8');
}, function(err) {

1 answers


В этом случае requireLib должно быть избыточным, как загружается независимо друг от друга require.js