我刚刚接手了一个以前的开发公司只完成了部分的网络项目。该网站显然由我不熟悉的 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.