我刚刚接手了一个以前的开发公司仅部分完成的网络项目。我不熟悉的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] }
以下是gruntfile:
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.
答案 0 :(得分:0)
grunt是任务运行器而不是服务器,因此您需要阅读如何使用grunt设置内容。 http://gruntjs.com/ 您的服务器是节点,它在本地运行。 task runner一句话:自动化。执行重复性任务(如缩小,编译,单元测试,掉毛等)时,您需要做的工作就越少。
我不熟悉grunt-bbb-server,但看起来你需要运行: 咕噜咕噜而不是咕噜声