简体   繁体   English

使用gulp构建durandaljs对于外部模块失败

[英]Building durandaljs with gulp fails for external modules

I'm using gulp-durandal to build our durandal app. 我正在使用gulp-durandal来构建我们的durandal应用程序。 It fails on our first module which has a depeendecy to knockout through: 它在我们第一个具有删除功能的模块上失败:

define(['knockout',.... define([''knockout',....

[09:35:27] Durandal Error: ENOENT, no such file or directory 'C:\\xxxxx\\app\\knockout.js' In module tree: company/viewmodels/edit [09:35:27] Durandal错误:ENOENT,没有这样的文件或目录'C:\\ xxxxx \\ app \\ knockout.js'在模块树中: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 ? 我已经将敲除定义为config.js中的补丁(标准requirejs方式),但似乎gulp-durandal无法解析config.js的路径吗?

'knockout': '../Scripts/lib/knockout/knockout-2.3.0', '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 ? 如何让gulp-durandal使用我们的配置路径,而不是尝试直接在app文件夹下解析模块? 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. 我尝试使用options.extraModules,但这仅允许您添加模块的路径,而不是模块的符号名,因此这似乎不是正确的方法。

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. 我的durandaljs应用程序的基本结构遵循我认为的标准准则,我在App文件夹下有一个config.js和main.js。

My config.js: 我的config.js:

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

My main.js 我的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: 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 ? 我想问题是如何将config.js路径加载到gulp中,以便正确解析路径? 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) 但是似乎require只需要一个字符串作为输入(我猜gulp中的require函数!= require.js中的require)

I believe the issue is that your gulp-durandal task needs configuration to mimic the config.js file. 我认为问题在于您的gulp-durandal任务需要进行配置以模仿config.js文件。 If you need further assistance please provide more code from your gulp-durandal task. 如果您需要进一步的帮助,请从“ gulp-durandal”任务中提供更多代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM