How to load modules concatenated with Gulp in Requirejs?

Asked

Viewed 21 times

1

My project has several AMD modules being loaded into the browser by Requirejs.

However, I am migrating from Javascript to Typescript and also want to use Gulp to transpose to Javascript and generate a file bundle.js which will contain all modules already transpilated and concatenated.

However, I don’t know how to carry this bundle.js in the browser.

Before using Typescript I did so:

  1. Set a file boot.js which explained the modules:
requirejs.config({
  baseUrl: '/',
  paths: {
    /* ========================== libs ========================== */
    jquery: '/node-dependencies/jquery/dist/jquery',
    ace: '/node-dependencies/ace-builds/src',
    vis: '/node-dependencies/visjs-network/dist/',
    jsYaml: '/node-dependencies/js-yaml/dist/js-yaml',
    bootstrap: '/node-dependencies/bootstrap/dist/js/bootstrap.bundle',
    fontawesome: '/node-dependencies/@fortawesome/fontawesome-free/js/all',
    toastr: '/node-dependencies/toastr/build/toastr.min',
    /* ========================== app ========================== */
    aceEditor: 'app/js/aceEditor',
    btnLoadFile: 'app/js/btnLoadFile',
    btnValidateYaml: 'app/js/btnValidateYaml',
    graphEditor: 'app/js/graphEditor',
    btnBuild: 'app/js/btnBuild',
    btnExecute: 'app/js/btnExecute',
    loadingScreen: 'app/js/loadingScreen',
    Task: 'app/js/Task',
    Digraph: 'app/js/Digraph',
    experiment: 'app/js/experiment',
    app: 'app/js/app',
    yamlParser: 'app/js/yamlParser',
    taskInfo: 'app/js/taskInfo',
    Button: 'app/js/Button'
  }
});

requirejs(['jquery'], function () {
  requirejs(['bootstrap', 'fontawesome'], function () {
    requirejs(['loadingScreen'], function (loadingScreen) {
      loadingScreen.show();
      requirejs([
        'aceEditor',
        'btnLoadFile',
        'graphEditor',
        'btnExecute',
        'btnValidateYaml',
        'btnBuild'], function () {
        requirejs(['app'], () => $(document).ready(loadingScreen.hide));
      });
    });
  });
});
  1. Carried the boot.js in the browser as follows:
<script src="/node-dependencies/requirejs/require.js" data-main="/app/js/boot.js"></script>

My doubts are:

  1. Given the file bundle.js generated by Gulp, as I do for it to be loaded in the browser?

  2. I still need to clarify the modules in boot.js and they’ll already be inside the same file?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.