RequireJS multipage r.js

时间:2015-06-09 06:26:08

标签: javascript requirejs amd r.js tweenlite

我有一个使用RequireJS构建的相当大的应用程序,我尝试使用r.js优化模块。

但无论我做什么,我总会得到同样恼人的错误。

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

看起来我的路径cssplugin被忽略了,这是我的build.js文件:

{
        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"
          }
        ]
    }

嗯..我知道它看起来很多信息,但这是我的commom.js文件(RequireJS配置):

(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);

文件按此结构组织:

Estrutura de Pastas

好吧,在我的网站上,脚本按以下方式加载:

<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>

因此,全局JS对象(由PHP脚本构建)具有requirejs.config对象的URL。加载commom.js时,RequireJS会询问core / Main.js文件。当加载core / Main时,它将首先询问utils / Vendor模块。该模块加载所有第三方脚本(如jQuery,TweenLite,CSSPlugin等)。只有在加载这些文件时,Main.js才会询问页面控制器文件(它也会使用许多其他文件)。

所以,我正在尝试使用r.js构建所有这些模块:

所有第三部分脚本:utils / Vendor
主要内容:核心/主要
所有其他主页控制器:
controllers / MapsHome,controllers / SuperHome,controllers / Register,controllers / hotel / HotelHome

每次运行r.js时,tweelite或cssplugin都会出错,并且优化会被终止。

0 个答案:

没有答案