2

I'm using gulp-durandal to build our durandal app. It fails on our first module which has a depeendecy to knockout through:

define(['knockout',....

[09:35:27] Durandal Error: ENOENT, no such file or directory 'C:\xxxxx\app\knockout.js' In module tree: company/viewmodels/edit

at Object.fs.openSync (fs.js:438:18)

I have knockout defined as a patch in config.js (standard requirejs way) but it seems gulp-durandal does not resolve paths from config.js ?

'knockout': '../Scripts/lib/knockout/knockout-2.3.0',

How do you get gulp-durandal to use our config paths instead of trying to resolve the modules directly under the app folder ? I tried using options.extraModules but that only allows you to add paths to modules, not symbolic names for the module so that doesn't seem to be the correct way.

The basic structure of my durandaljs app follows the standard guidelines I believe, I have a config.js and main.js under the App folder.

My config.js:

define([], function() {
return {
    paths: {
        'text': '../Scripts/lib/require/text',
        'durandal': '../Scripts/durandal',
        'plugins': '../Scripts/durandal/plugins',   

My main.js

require(['config'], function(config) {
require.config(config);

require(['durandal/system', 'durandal/app', 'durandal/viewLocator', 'plugins/widget', 'custombindings'],
    function(system, app, viewLocator, widget) {
        ..... app code here.....

}

gulpfile.js:

var gulp = require('gulp');

var durandal = require('gulp-durandal');

require(['App/config'], function(config){
  console.log('loaded config');
});

gulp.task('durandal', function(){
durandal({
baseDir: 'app', //same as default, so not really required.
main: 'main.js', //same as default, so not really required.
output: 'main.js', //same as default, so not really required.
almond: true,
minify: true,
require:true
})
.pipe(gulp.dest('dir/to/save/the/output'));
});

I guess the question is how do I load my config.js paths into gulp so the paths are resolved correctly ? I tried:

var gulp = require('gulp');

var durandal = require('gulp-durandal');

require(['App/config'], function(config){
  console.log('loaded config');
});

But it seems require only wants a string as input (I guess require function in gulp != require from require.js)

user810365
  • 21
  • 3

1 Answers1

0

I believe the issue is that your gulp-durandal task needs configuration to mimic the config.js file. If you need further assistance please provide more code from your gulp-durandal task.

Matthew James Davis
  • 12,134
  • 7
  • 61
  • 90
  • Sounds reasonable, but how do i requre my config.js file from gulpfile.js ? I tried something like: var gulp = require('gulp'); var durandal = require('gulp-durandal'); require(['App/config'], function(config){ console.log('loaded config'); }); But I guess require in gulp is not the same as from require.js ? Sorry I'm a gulp noob. – user810365 Mar 06 '15 at 08:27
  • 1
    Obviously we call require.config( config ) with the config object containing all the paths, but how do I do that in gulp ? I would need a require.js object first I guess ? There seems to be something missing here, all durandal apps I know of use require.js for amd, how could gulp-durandal possibly work without configuring require.js first ? – user810365 Mar 06 '15 at 08:36
  • Please add details on how to load in a config.js (that isn't inside of the main.js file) into gulp, if you know how. Thanks. – AlignedDev May 02 '16 at 14:31