I am struggling with the requirejs optimizer and non AMD modules

♀尐吖头ヾ 提交于 2019-12-03 10:54:57

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

ProVega

See mainConfigFile. This was put into place so you do not have to copy your require configuration into runtime/optimize-time files, keeping your build DRY:

//By default all the configuration for optimization happens from the command
//line or by properties in the config file, and configuration that was
//passed to requirejs as part of the app's runtime "main" JS file is *not*
//considered. However, if you prefer the "main" JS file configuration
//to be read for the build so that you do not have to duplicate the values
//in a separate configuration, set this property to the location of that
//main JS file. The first requirejs({}), require({}), requirejs.config({}),
//or require.config({}) call found in that file will be used.
mainConfigFile: '../some/path/to/main.js',
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!