How to Migrate Gruntfile.js Configuration Into build.json

If you use Grunt tasks to optimize your application, it's important to migrate configuration you've already defined in the Gruntfile.js file into build.json. Without this definition in build.json, resource optimization that occurs by default when your application is shared or deployed won't include your customizations.

  1. Select the web application in the Navigator, then click Settings to open the app-level Settings editor.
  2. Click Open Build Configuration under Optimization to open your application's build.json file. If you don't see this option, click Create Build Configuration to create the build.json file (under /webApps/app_name/settings) and open it from within the Settings editor.
  3. Add this snippet to build.json:
    {
        "optimize": {
            "require-js": {
                "emptyPaths": [
                ],
                "vb-bundles-config": {
                }
            }
        }
    }
  4. Open your application's Gruntfile.js file (located at the root of your visual application in Source view).
  5. Move the following configuration from Gruntfile.js to build.json:
    • Move the content of vb-require-bundle.options.bundles from Gruntfile.js into optimize.require-js.vb-bundles-config in build.json.
    • Move the content of vb-require-bundle.options.emptyPaths, if defined, from Gruntfile.js into optimize.require-js.emptyPaths in build.json.
    Remember to fix the syntax for JSON schema. For example, here's a side-by-side comparison of the configuration in Gruntfile.js and build.json:
    Gruntfile.js build.json
    'use strict';
    module.exports = (grunt) => {
        require('load-grunt-tasks')(grunt);
        grunt.initConfig({
            "vb-require-bundle": {
                options: {
                    emptyPaths: [
                        'ckeditor',
                    ],
                    "bundles": {
                        "vb-app-bundle": {
                            "modules": {
                                "find": [
                                    "^flows/",
                                    "^pages/",
                                    "^resources/",
                                    "!^services/",
                                ],
                            },
                        },
                    },
                },
            },
        });
    };
    {
        "optimize": {
            "require-js": {
                "emptyPaths": [
                    "ckeditor"
                ],
                "vb-bundles-config": {
                    "vb-app-bundle": {
                        "modules": {
                            "find": [
                                "^flows/",
                                "^pages/",
                                "^resources/",
                                "!^services"
                            ]
                        }
                    }
                }
            }
        }
    }
  6. Remove vb-require-bundle from Gruntfile.json, so your file looks something like this:
    module.exports = (grunt) => {
        require('load-grunt-tasks')(grunt);
    };