Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将预编译视图与RequireJS一起使用(可以编译)_Javascript_Node.js_Requirejs_Ejs_Canjs - Fatal编程技术网

Javascript 将预编译视图与RequireJS一起使用(可以编译)

Javascript 将预编译视图与RequireJS一起使用(可以编译),javascript,node.js,requirejs,ejs,canjs,Javascript,Node.js,Requirejs,Ejs,Canjs,我使用了可以编译NodeJS模块,该模块将CanJS EJS视图编译成单个JavaScript文件,用于我的项目中闪电般快速的生产应用程序。(我使用canjs、requirejs、ejs.js作为模板): 我按照这些指示设置我的咕噜任务 my Grunfile.js: module.exports = function (grunt) { // Project configuration. grunt.initConfig({ cancompile: { options

我使用了可以编译NodeJS模块,该模块将CanJS EJS视图编译成单个JavaScript文件,用于我的项目中闪电般快速的生产应用程序。(我使用canjs、requirejs、ejs.js作为模板):

我按照这些指示设置我的咕噜任务

my Grunfile.js:

module.exports = function (grunt) {

// Project configuration.
grunt.initConfig({
    cancompile: {
        options: {
            version: '1.1.8',
            wrapper: 'define(["can/view/ejs"], function(can) { {{{content}}} });'
        },
        dist: {
            src: ['**/*.ejs', '!node_modules/**/*.ejs', '!www-built/**/*.ejs'],
            dest: 'www-built/js/views.production.js'
        }
    },
    uglify: {
        //configuracion uglify
        options: {
            mangle: false,
            compress: {
                drop_console: true
            },
            preserveComments : false
        },
        js: {
            files: [{
                cwd: 'www-built/js/',  // ruta de nuestro javascript fuente
                expand: false,    // ingresar a las subcarpetas
                src: 'views.production.js',     // patrón relativo a cwd
                dest: 'www-built/js/'  // destino de los archivos compresos
            }]
        }
    }

});
/*carichiamo i moduli*/
grunt.loadNpmTasks('can-compile');
grunt.loadNpmTasks('grunt-contrib-uglify');

/*registriamo il task*/
grunt.registerTask('default', ['cancompile']);


};
grunt任务可以工作,它创建了一个编译的js文件,但是当我运行require构建时,它不包括生成的文件和生产中的视图

我得到了这个错误:

can.view: No template or empty emplate:js/app/common/calendar/views/init.ejs
我在项目目录中创建了一个文件views.production.js,内容如下:

define('views', function() {});
然后在我的build.js文件应用程序中,我放了以下内容:

 "paths" : {
    "app" : "../app",
    "tools" : "../../../tools",
    "jquery" : "jquery-2.0.3.min",
    "jquery-ui" : "plugins/jquery-ui-1.10.4.custom.min",
    "jquery-ui-touch-punch" : "plugins/jquery.ui.touch-punch.min",
    "bootstrap" : "bootstrap.min",
    "underscore" : "underscore.min",
    "can" : "can",
    "aria" : "aria",
    "models" : "../app/common/models",
    //folder directory for documentation
    "doc" : "../doc",
    "async" : "require/async",
    "goog" : "require/goog",
    "propertyParser" : "require/propertyParser",
    "google-api" : "aria/google_api/google-api-engine",
    "google-maps" : "aria/google_api/google-maps-engine",
    "collaboration" : "../app/collaboration",
    "swipe" : "plugins/swipe2",
    "animend-transend" : "plugins/jquery.animend.transend",
    "jquery-validate" : "plugins/jquery.validate.min",
    "jcrop" : "plugins/jcrop/js/jquery.Jcrop.min",
    "spin" : "plugins/spin",
    "ftscroller" : "plugins/ftscroller",
    "owl-carousel" : "plugins/owl.carousel.min",
    'shared_resource' : '../shared_resource',
    'views' : '../views.production'
}
然后在应用程序的commons.js文件中,我提出了一个要求:

require([
    'jquery',
    'aria',
    'app/common/error_handler',
    'app/common/vocal',
    'views'
], function (jQuery, AriaTouch) {
我的应用程序尝试调用ejs文件:

GET http://local.bst.prod/js/app/timeline/sidebar/bookmark/views/submenuBookmark.ejs 404 (Not Found)
common.js:4 Uncaught can.view: No template or empty 
template:js/app/timeline/sidebar/bookmark/views/submenuBookmark.ejs

你为什么用丑而不丑?如果您按照本节中的描述使用它,它将包含在构建中并且应该可以工作。您是对的,我将修改此部分,但问题是它不包含项目中的编译文件,您有什么想法吗?您可以通过编译和添加
define(['views'],function(){})轻松测试它在您的项目中。应该加载已编译的视图。如果它不起作用,你的路径可能是错误的。你能告诉我在哪里保存views.production.js文件吗?thanksIt并不重要,只要运行编译的位置与在应用程序中加载视图的位置相同。