>节点测试
> bower_components
>建立
>公开
> main.js
> build.js
运行优化器与r.js -o build.js和以下配置工作正常:
// main.js file requirejs.config({ baseUrl: '../bower_components',paths: { 'domready': 'domready/ready','jquery': 'jquery/jquery',} }); requirejs(['domready','jquery'],function (domReady,$) { domReady(function () { }); }); // build.js file ({ baseUrl: "bower_components",name: "./almond/almond",include: "./../public/main",out: "build/main.js",},preserveLicenseComments: false })
但是,如果我删除build.js中的路径配置,它不再工作:
Tracing dependencies for: ./almond/almond Error: ENOENT,no such file
or directory
‘C:\Users\Marco\Documents\Progetti\nodejs-opt\bower_components\domready.js’
In module tree:
../public/mainError: Error: ENOENT,no such file or directory
‘C:\Users\Marco\Documents\Progetti\nodejs-opt\bower_components\domready.js’
In module tree:
../public/main06001
我想要干,避免添加一个依赖关系两次.这可能吗?
解决方法
…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.
这样的东西
({ baseUrl: "bower_components",mainConfigFile: '/some/path/main.js',// adjust path as needed name: "./almond/almond",preserveLicenseComments: false })