I am struggling with the requirejs optimizer and non AMD modules

后端 未结 2 998
情深已故
情深已故 2021-02-13 15:19

I am struggling with the requirejs optimizer. This code will work if I just load it in the browser without optimization. If I run the optimizer I get

: ENOENT,          


        
2条回答
  •  北恋
    北恋 (楼主)
    2021-02-13 15:33

    The problem: the require.config() is not parsed by r.js. That configuration is only for runtime. For r.js we need to create another file to configure the paths and other stuff.

    Create a file (e.g app.build.js) and configure the paths

    ({
       appDir: "../",
       baseUrl: "./",
       dir: "dist",
       modules: [
            {
                name: "bootloader"
            }
        ],
        paths: {
           // libraries path
          "json": "lib/json2",
          "jquery": "lib/jquery",
          "underscore": "lib/underscore",
          "bootstrap": "lib/bootstrap",
          "backbone": "lib/backbone",
          "hogan": "lib/hogan",
    
           // require plugins
          "css": "lib/css",
          "hgn": "lib/hgn",
          "text": "lib/text"
       }
    })
    

    run the optimizer:

    $r.js -o app.build.js

    More details here: http://japhr.blogspot.it/2011/12/optimizing-requirejs-part-2.html

    Build file options: http://requirejs.org/docs/optimization.html#wholeproject

提交回复
热议问题