我对咕噜有一些问题,因为它似乎做了比我想做的更多的事情。我有两个文件夹,其中有两个本地的咕噜,但是当我从一个文件夹在本地启动它时,它也会做另一个文件夹中的“其他”咕哝应该做的事情。我在每个文件夹中都有一个index.html文件,具有不同的代码,导致不同的JavaScript (.js)文件,但是grunt同时执行这两个文件。(首先是另一个文件夹中的一个,然后是我启动它的文件夹中的那个。)
我目前没有发布任何代码,因为我觉得这个问题应该是相对独立的,但是如果有人认为有必要回答这个问题,我会这么做的。
你认为这个问题来自于我在本地的咕噜声之前安装的全球咕噜声吗?(也就是说,它搜索所有文件并执行指令?)
有什么暗示,想法,建议吗?谢谢。
编辑:更好地描述我的文件结构。在桌面上,我有两个文件夹(项目),并安装了两个本地grunts。在第一个项目中,index.html是:
<html>
<head><title>Testing grunt</title></head>
<body>
<script src="scripts/app.js"></script>
<h1>It works!</h1>
</body>
</html>在这里,app.js调用另一个.js文件,该文件会触发一条警报消息。
作为一种测试,这是可行的。但是在第二个项目(文件夹)中,这个文件夹也在桌面中,index.html是:
<!DOCTYPE html>
<html>
<head>
<title>Cloud clicker game</title>
</head>
<body>
<h1>Hello!!!</h1>
<div id="game"></div>
<script src="scripts/phaser.min.js"></script>
<script src="scripts/app.js"></script>
</body>
</html> 导致了一个不同的app.js文件,这是我使用phaser.js库做的一个小示例游戏。
问题是,当我从“游戏”文件夹中发出咕噜声时,都会发出“你好!”第一个文件夹中的警报会显示出来,而不是由游戏文件夹中的咕噜声启动的游戏。没有游戏开始,但这是另一个问题。首先,我需要消除警报(即正在启动的“其他”index.html )
希望这有助于更好地理解问题/情况。
编辑:这是我的gruntfile.js
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
browserify: {
main: {
options: {
browserifyOptions: {
debug: true
},
transform: [["babelify", { "presets": ["es2015"] }]]
},
src: 'src/app.js',
dest: 'scripts/app.js'
}
},
watch: {
files: [ 'src/**/*.js' ],
tasks: ['browserify'],
options: {
spawn: false,
},
},
connect: {
target:{
options: {
port: 9001
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-browserify');
grunt.registerTask('default', [ 'connect', 'watch']);
};编辑:咕噜的输出--详细的
grunt --verbose Initializing
Command-line options: --verbose
Reading "gruntfile.js" Gruntfile...OK
Registering Gruntfile tasks.
Reading package.json...OK
Parsing package.json...OK
Initializing config...OK
Registering "grunt-contrib-connect" local Npm module tasks.
Reading /home/alessandro/Desktop/Cloud_Clicker_Game/node_modules/grunt-contrib-connect/package.json...OK
Parsing /home/alessandro/Desktop/Cloud_Clicker_Game/node_modules/grunt-contrib-connect/package.json...OK
Loading "connect.js" tasks...OK
+ connect
Registering "grunt-contrib-watch" local Npm module tasks.
Reading /home/alessandro/Desktop/Cloud_Clicker_Game/node_modules/grunt-contrib-watch/package.json...OK
Parsing /home/alessandro/Desktop/Cloud_Clicker_Game/node_modules/grunt-contrib-watch/package.json...OK
Loading "watch.js" tasks...OK
+ watch
Registering "grunt-browserify" local Npm module tasks.
Reading /home/alessandro/Desktop/Cloud_Clicker_Game/node_modules/grunt-browserify/package.json...OK
Parsing /home/alessandro/Desktop/Cloud_Clicker_Game/node_modules/grunt-browserify/package.json...OK
Loading "browserify.js" tasks...OK
+ browserify
Loading "gruntfile.js" tasks...OK
+ default
No tasks specified, running default tasks.
Running tasks: default
Running "default" task
Running "connect" task
Running "connect:target" (connect) task
Verifying property connect.target exists in config...OK
File: [no files]
Options: protocol="http", port=9001, hostname="0.0.0.0", base=".", directory=null, keepalive=false, debug=false, livereload=false, open=false, useAvailablePort=false, onCreateServer=null, middleware=null
Reading /home/alessandro/Desktop/Cloud_Clicker_Game/node_modules/grunt-contrib-connect/tasks/certs/server.key...OK
Reading /home/alessandro/Desktop/Cloud_Clicker_Game/node_modules/grunt-contrib-connect/tasks/certs/server.crt...OK
Reading /home/alessandro/Desktop/Cloud_Clicker_Game/node_modules/grunt-contrib-connect/tasks/certs/ca.crt...OK
Started connect web server on http://localhost:9001
Running "watch" task
Waiting...
Verifying property watch exists in config...OK
Watching src/app.js for changes.发布于 2016-12-25 21:52:18
因此,您从未实际运行browserify任务。当您在命令行上运行grunt而没有指定特定任务时,它将运行default任务,在本例中,该任务只运行connect和watch。
有两种方法可以修复:
grunt browserify['browserify', 'connect', 'watch']https://stackoverflow.com/questions/41314000
复制相似问题