0

我刚刚接手了一个以前的开发公司只完成了部分的网络项目。该网站显然由我不熟悉的 Grunt 服务器提供服务。

当我运行时grunt,我得到了这个错误:

$ grunt

Loading "server.js" tasks...ERROR
>> TypeError: Cannot read property 'prototype' of undefined

Running "clean:0" (clean) task
Cleaning dist/...OK

Running "jshint:files" (jshint) task
>> 53 files lint free.

Running "processhtml:release" (processhtml) task

Running "copy:release" (copy) task

Running "requirejs:production" (requirejs) task
{ [Error: Error: Module loading did not complete for: main, app, backbone, marionette, views/layout/header, context/context, context/user, context/utils, 
The following modules share the same URL. This could be a misconfiguration if that URL only has one anonymous module in it:
/home/***/****/**/bower_components/backbone/backbone.js: backbone, backbone
    at Function.build.checkForErrors (/home/***/*****/*****/node_modules/grunt-contrib-requirejs/node_modules/requirejs/bin/r.js:31556:19)
]
  originalError: 
   [Error: Module loading did not complete for: main, app, backbone, marionette,
   The following modules share the same URL. This could be a misconfiguration if that URL only has one anonymous module in it:
   /home/***/***/***/bower_components/backbone/backbone.js: backbone, backbone] }

以下是 grunt 文件:

module.exports = function(grunt) {

    // Configuration
    grunt.initConfig({
        /*------- JS Hint -------*/
        jshint: {
            files: ['Gruntfile.js', 'src/**/*.js', '!src/manual_tp/**/*.js' ,'!src/manual_tp/*.js', '!src/models/analytics/analytics.js'],
            options: {
                globals: {
                    jQuery: true
                }
            }
        },
        /*------- Clean -------*/
        clean: ["dist/"],
        /*------- Process HTML -------*/
        processhtml: {
            release: {
                files: {
                    'dist/index.html': ['index.html']
                },
                options: {
                        process: true
                }
            }
        },
        /*------- Copy -------*/
        copy: {
            release: {
                files: [
                {src:['static/**'], dest:'dist/'}
                ]
            }
        },
        /*------- RequireJS -------*/
        requirejs: {
            production: {
                options: {
                    baseUrl: "src/",
                    mainConfigFile: 'src/config.js',
                    generateSourceMaps: true,
                    out: "dist/static/js/source.min.js",
                    optimize: "uglify2",
                    name: "almond",
                    wrap: true,
                    preserveLicenseComments: false,
                    useStrict: true,
                    findNestedDependencies: true
                }
            }
        },
        /*------- Less -------*/
        less: {
            run: {
                options: {
                    paths: ["src/less"]
                },
                files: {
                    "dist/static/css/styles.css": "src/less/index.less"
                }
            }
        },
        /*------- CSS Min -------*/
        cssmin: {
            release: {
                files: {
                    "dist/static/css/styles.min.css": ["dist/static/css/styles.css"]
                }
            }
        },
        /*------- Server -------*/
        server: {
            options: {
                host: "127.0.0.1",
                port: 80
            },
            development: {},
            release: {
                options: {
                    prefix: "dist"
                }
            }
        },
        /*------- Grunt Watch -------*/
        /* If any of the js/html/less files change, update the application */
        watch: {
            js: {
                files: ['src/**/*.js'],
                tasks: ['requirejs']
            },
            html: {
                files: ['src/templates/**/*html'],
                tasks: ['requirejs']
            },
            less: {
                files: ['src/less/**/*less'],
                tasks: ['less', 'cssmin']
            },
            images: {
                files: ['src/images/**/*.{png,jpg,gif}'],
                tasks: ['imagemin']
            }
        },
        /*------- Grunt Image Compression -------*/
        imagemin: {
            dist: {
                options: {
                    optimizationLevel: 3
                },
                files: [{
                     expand: true,
                     cwd: 'src/images',
                     src: ['**/*.{png,jpg,gif,ico}'],
                     dest: 'dist/static/img/'
                }]
            }
        }

    });

    // Load NPM Tasks
    grunt.loadNpmTasks('grunt-contrib-jshint');
    grunt.loadNpmTasks('grunt-contrib-clean');
    grunt.loadNpmTasks('grunt-processhtml');
    grunt.loadNpmTasks('grunt-contrib-copy');
    grunt.loadNpmTasks('grunt-contrib-requirejs');
    grunt.loadNpmTasks('grunt-contrib-less');
    grunt.loadNpmTasks('grunt-contrib-cssmin');
    grunt.loadNpmTasks('grunt-bbb-server');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-contrib-imagemin');

// Build
    grunt.registerTask('build', [
        'clean',
        'jshint',
        'processhtml',
        'copy',
        'requirejs',
        'less',
        'cssmin',
        'imagemin'
    ]);


    grunt.registerTask('serve', ['server']); // Start local server on the main directory
    grunt.registerTask('servedist', ['server:release']); // Start local server on the dist directory

// Default grunt command
    grunt.registerTask('default', [
        'build'
    ]);

};

该服务器是否应该在生产环境中使用?如果还有其他原因,这可能会失败?

更新

运行grunt serve给我以下错误:

Loading "server.js" tasks...ERROR
>> TypeError: Cannot read property 'prototype' of undefined
Warning: Task "server" not found. Use --force to continue.

Aborted due to warnings.
4

1 回答 1

0

grunt 是任务运行器而不是服务器,因此您需要阅读如何使用 grunt 进行设置。 http://gruntjs.com/ 你的服务器是节点并且它在本地运行。任务运行器 一言以蔽之:自动化。在执行压缩、编译、单元测试、linting 等重复性任务时,您要做的工作越少。

我不熟悉 grunt-bbb-server 但看起来你需要运行:grunt serve 而不是 grunt

于 2016-06-11T15:27:06.150 回答