Dưới đây là (một phần của) cấu trúc thư mục của tôi:Tránh sao chép cấu hình "đường dẫn" trong tệp chính của RequireJS và tệp xây dựng r.js?
- nút kiểm tra
- bower_components
- build
- công
- main.js
- build.js
Chạy tôi ưu hoa với r.js -o build.js
và cấu hình sau hoạt động tốt:
// 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",
paths: {
'domready': 'domready/ready',
'jquery': 'jquery/jquery',
},
preserveLicenseComments: false
})
Tuy nhiên, nếu tôi loại bỏ paths
cấu hình trong build.js
nó không hoạt động nữa:
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/main
Error: Error: ENOENT, no such file or directory 'C:\Users\Marco\Documents\Progetti\nodejs-opt\bower_components\domready.js' In module tree: ../public/main
at Object.fs.openSync (fs.js:427:18)
tôi 'muốn được DRY, tránh thêm phụ thuộc hai lần. Điều này có thể không?
Perfect !! ! Cảm ơn bạn rất nhiều! – gremo