RequireJS multipage r.js

175 views Asked by At

I have a quite large app built with RequireJS and I'm trying optimise the modules with r.js.

But no matter what I do, I always get the same annoying error.

me:  ~/WORK/LAB/require_r_js/js
→ r.js -o build.js
Optimizing (standard.keepLines.keepWhitespace) CSS file: /<path_to_my_js_folder>/js/dist/vendor/tinyscrollbar/tinyscrollbar.css

Tracing dependencies for: utils/Vendor
Error: ENOENT, no such file or directory
'/<path_to_my_js_folder>/js/dist/TweenLite.js'
In module tree:
    utils/Vendor
      cssplugin

It looks like my path cssplugin is been ignored, here is my build.js file:

{
        mainConfigFile : "core/commom.js",
        appDir: '.',
        baseUrl: ".",
        removeCombined: true,
        findNestedDependencies: true,
        dir: "./dist",

        paths: {
          tweenlite: "vendor/greensock/TweenLite.min",
          cssplugin: "vendor/greensock/plugins/CSSPlugin.min",
          easepack: "vendor/greensock/easing/EasePack.min",
          jquery: "vendor/jquery/jquery-1.11.2.min",
          signals: "vendor/signals/signals",
          underscore: "vendor/underscore/underscore-min",
          retina: "vendor/retinajs/retina-1.1.0",
          tinyscrollbar: "vendor/tinyscrollbar/jquery.tinyscrollbar.min",
          async: 'vendor/millermedeiros/requirejs-plugins/async',
          simpleWeather: 'vendor/simpleWeather/jquery.simpleWeather.min'
        },

        shim: {
          underscore: {
            exports: "_"
          },
          jquery: {
            exports: "jQuery"
          },
          simpleWeather: {
            exports: "simpleWeather",
            deps: ["jquery"]
          }
        },

        modules: [
            { name: "utils/Vendor" },
          {
            name: "core/Main",
            exclude: ['utils/Vendor']
          },
          {
            name: "controllers/MapsHome"
          },
          {
            name: "controllers/SuperHome"
          },
          {
            name: "controllers/Register"
          },
          {
            name: "controllers/hotel/HotelHome"
          }
        ]
    }

Well.. I know it looks a lot of information, but this is my commom.js file (the RequireJS config):

(function() {
      requirejs.config({
        baseUrl: "../",
        waitSeconds: 120,
        paths: {
          tweenlite: "vendor/greensock/TweenLite.min",
          cssplugin: "vendor/greensock/plugins/CSSPlugin.min",
          easepack: "vendor/greensock/easing/EasePack.min",
          jquery: "vendor/jquery/jquery-1.11.2.min",
          jmask: "vendor/igorescobar/jquery-mask-plugin.min",
          signals: "vendor/signals/signals",
          underscore: "vendor/underscore/underscore-min",
          retina: "vendor/retinajs/retina-1.1.0",
          tinyscrollbar: "vendor/tinyscrollbar/jquery.tinyscrollbar.min",
          async: 'vendor/millermedeiros/requirejs-plugins/async',
          simpleWeather: 'vendor/simpleWeather/jquery.simpleWeather.min'
        },
        shim: {
          underscore: {
            exports: "_"
          },
          jquery: {
            exports: "jQuery"
          },
          simpleWeather: {
            exports: "simpleWeather",
            deps: ["jquery"]
          },
          facebook: {
            exports: 'FB'
          }
        }
      });

}).call(this);

The files are organized in this structure:

Estrutura de Pastas

Well, in my website the scripts are loaded as this:

<script type="text/javascript">
    require([globalServerConf.requireJSConfURL], function() {

        require(['core/Main'], function(Main) {
            var m = new Main();
            // The name of the Page Controller is set by a PHP Variable:
            m.init("{{$jsController}}");
        });
    });
</script>

So, a global JS object (built by a PHP script) has the URL to the requirejs.config object. When commom.js is loaded, RequireJS asks for core/Main.js file. When core/Main is loaded, it will ask first for the utils/Vendor module. This module loads all third part scripts (like jQuery, TweenLite, CSSPlugin, etc etc). Only when these files are loaded, Main.js asks for the page controller file (which makes use of many other files as well).

So, I am trying to build with r.js all these modules:

All third part scripts: utils/Vendor
Main script: core/Main
All other main pages controllers:
controllers/MapsHome, controllers/SuperHome, controllers/Register, controllers/hotel/HotelHome

Every time I run r.js, tweelite or cssplugin makes that error and the optimization is killed.

0

There are 0 answers