I'm using gulp-durandal but it only support building into one single file.
Now I want to use requirejs and the bundles
feature, but can't make it work yet.
This is the gulp file I used:
var requirejs = require('requirejs');
var gulp = require('gulp');
var requireJsOptimizerConfig = {
out: '../dist/main-built.js',
baseUrl: 'app',
name: 'main',
paths: {
requireLib: '../scripts/require',
},
include: [
"requireLib",
],
insertRequire: ['main'],
bundles: { },
mainConfigFile: 'main.js',
};
gulp.task('build', function () {
requirejs.optimize(requireJsOptimizerConfig);
});
and the main.js
file looks like this:
requirejs.config({
paths: {
'text': '../lib/require/text',
'durandal':'../lib/durandal/js',
'plugins' : '../lib/durandal/js/plugins',
'transitions' : '../lib/durandal/js/transitions',
'knockout': '../lib/knockout/knockout-3.4.0',
'bootstrap': '../lib/bootstrap/js/bootstrap',
'jquery': '../lib/jquery/jquery-1.9.1'
},
shim: {
'bootstrap': {
deps: ['jquery'],
exports: 'jQuery'
}
}
});
define([...], function(){ ... });
Although gulp ran without any error, when I went to the site, there is one strange HTTP request:
http://localhost:8080/Scripts/durandal/plugins/widget.js?v=1.0.0.0
I'm guessing that the plugins inside the folder durandal/js/plugins
is not compiled correctly. How can I solve this?
I tried specify the widget
library explicitly but it still looking for the Scripts
folder:
paths: {
requireLib: '../scripts/require',
'widget': '../Scripts/durandal/plugins/widget',
},
include: [
"requireLib",
'widget',
],
I also don't understand how durandal can run in the first place. Because, as far as I know, you have to define each individual modules, so how can this config work:
paths: {
plugins' : '../lib/durandal/js/plugins'
}