Search code examples
javascriptrequirejsr.js

RequireJS: Prevent copying text! files after inline


I have an r.js build which works. However, it copies all of the files underneath my template/ directory to the dist/ directory even though it inlined all of their text. I have removeCombined: true set which I would expect to prevent this.

If I include the template/ directory in my fileExclusionRegExp then my build fails. I have tried excluding with empty: but haven't had much success.

Is this possible? Or do I need a post-build step to clean up these files if I want to inline them?

requirejs: {
    production: {
        //  All r.js options can be found here: https://github.com/jrburke/r.js/blob/master/build/example.build.js
        options: {
            appDir: 'src',
            dir: 'dist/',
            //  Inlines the text for any text! dependencies, to avoid the separate
            //  async XMLHttpRequest calls to load those dependencies.
            inlineText: true,
            stubModules: ['text'],
            useStrict: true,
            mainConfigFile: 'src/js/common/requireConfig.js',
            //  List the modules that will be optimized. All their immediate and deep
            //  dependencies will be included in the module's file when the build is done
            modules: [{
                name: 'background/main',
                include: ['background/plugins']
            }, {
                name: 'background/application',
                exclude: ['background/main']
            }, {
                name: 'foreground/main',
                include: ['foreground/plugins']
            }, {
                name: 'foreground/application',
                exclude: ['foreground/main']
            }],
            //  Skip optimizins because there's no load benefit for an extension and it makes error debugging hard.
            optimize: 'none',
            optimizeCss: 'none',
            preserveLicenseComments: false,
            //  Don't leave a copy of the file if it has been concatenated into a larger one.
            removeCombined: true,
            fileExclusionRegExp: /^\.|vsdoc.js$|\.example$|test|test.html|less$/
        }
    }
}

Solution

  • Well, 10 months later and I just had the same question for a different project.

    Assuming this is not possible and that a file-exclusion regexp should be used. However, that's scary because it could possibly exclude files which are not being loaded via text!