Requirejs optimizer - need help optimizing our application

We have a large-scale javascript application that we are trying to integrate and minimize using grunt-contrib-requirejs. We use the Aura structure. We use the gazebo to pull dependencies from other repositories into our main application.

Here is our structure

- app/  
   |  
   |_ main.js  
   |_ index.html  
   |_ css
   |_ bower_components/  
      |_ core/
      |_ widget1/  
          |_ main.js  
          |_ views/  
          |_ models/  
      |_ widget2/  
      |_ extension1/  
      |_ extension2/  
      |_ other third party libraries, etc
- Gruntfile.js
- bower.json

main.js:

requirejs.config({
    shim: {
        ...
    },
    paths: {
       'core': 'bower_components/core/app/main',
       'aura': 'bower_components/aura/dist/',
       'jquery': 'bower_components/jquery/jquery',
       'backbone': ...,
       ... lots of other paths
    }
});
define(['core', 'jquery', 'jqueryui'], function(core, $) {
    // Here we start Aura, which finds our extensions and widgets in
    // bower_components
});  

Our current requirejs task :

requirejs: {
    compile: {
        options: {
            mainConfigFile: 'app/main.js',
            name: 'main',
            include: ['bower_components/widget1/main', 'bower_components/widget2/main',
                'bower_components/extension1/main', 'bower_components/extension2/main'],
            exclude: ['jquery'],
            insertRequire: ['main'],
            out: 'dist/app.js'
        }
    }
}

This is consistent with our application / main and its dependencies, but when we try to run it, we get errors like:
  GET http: //www.my-machine: 8080 / bower_components / underscore / underscore.js 404 (not found) although underscore is the dependency of many widgets that we turn on.

r.js , .
, :

# 2: ​​

- dist/  
    |_ index.html // copied using grunt copy
    |_ css        // copied using grunt copy
    |_ app.js     // Built with grunt requirejs

UPDATE
underscore , , - :

Failed to load resource: the server responded with a status of 404 (Not Found)
http://my-machine.com:8080/bower_components/core/app/main.js  

, , :

define("bower_components/core/app/main.js", ["aura/aura", "bootstrap"], function(){
...
});

# 3
, ! core/app/main.js :

define(['aura', 'bootstrap'], function(Aura) {
    ...
});
+4
2

:

define("bower_components/core/app/main.js", ["aura/aura", "bootstrap"], function(){
...
});

. , , , , , bower_components/core/app/main.js, :

define("core", ...

core - paths 'core': 'bower_components/core/app/main'.

, 'bower_components/core/app/main.js' include . include, . , include , , 'bower_components/core/app/main.js' . define require.

+3

:

, . . , : http://requirejs.org/docs/api.html#modulename

-, , baseUrl . BaseUrl "app/" , . : http://requirejs.org/docs/api.html#config-baseUrl , .js, baseUrl .

, :

"bower_components/core/app/main.js" define. , Url .js.

+2

Source: https://habr.com/ru/post/1524364/


All Articles