咕噜声的问题
Problems with grunt
我对 grunt 有一些疑问,因为它做的事情似乎比我想要的多。我有两个文件夹,里面有两个本地 grunt,但是当我从一个文件夹在本地启动它时,它也执行另一个文件夹中的 "other" grunt 应该做的事情。我在每个文件夹中都有一个 index.html 文件,其中包含不同的代码,导致不同的 JavaScript (.js) 文件,但是 grunt 执行了这两个文件。 (首先是另一个文件夹中的那个,然后是我启动它的文件夹中的那个。)
我目前不发布任何代码,因为我觉得这个问题应该是相对代码无关的,但是如果有人认为有必要回答这个问题,我会做的。
您认为问题出在我安装本地 grunt 之前安装的全局 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 库制作的一个小示例游戏。
问题是,当我从 "game" 文件夹启动 grunt 时,第一个文件夹中的 "Hello!!!" 和警报都出现了,而不是应该由 grunt 启动的游戏在游戏文件夹中。没有比赛开始,但这是另一个问题。首先,我需要摆脱警报(即 "other" 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
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.
因此,您实际上从未 运行 执行 browserify
任务。当您在命令行上 运行 grunt
时未指定特定任务,则它 运行 是 default
任务,在这种情况下只有 运行 connect
和 watch
.
有两种修复方法:
- 只需在命令行上调用
grunt browserify
- 将默认任务更改为:
['browserify', 'connect', 'watch']
我对 grunt 有一些疑问,因为它做的事情似乎比我想要的多。我有两个文件夹,里面有两个本地 grunt,但是当我从一个文件夹在本地启动它时,它也执行另一个文件夹中的 "other" grunt 应该做的事情。我在每个文件夹中都有一个 index.html 文件,其中包含不同的代码,导致不同的 JavaScript (.js) 文件,但是 grunt 执行了这两个文件。 (首先是另一个文件夹中的那个,然后是我启动它的文件夹中的那个。)
我目前不发布任何代码,因为我觉得这个问题应该是相对代码无关的,但是如果有人认为有必要回答这个问题,我会做的。
您认为问题出在我安装本地 grunt 之前安装的全局 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 库制作的一个小示例游戏。
问题是,当我从 "game" 文件夹启动 grunt 时,第一个文件夹中的 "Hello!!!" 和警报都出现了,而不是应该由 grunt 启动的游戏在游戏文件夹中。没有比赛开始,但这是另一个问题。首先,我需要摆脱警报(即 "other" 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
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.
因此,您实际上从未 运行 执行 browserify
任务。当您在命令行上 运行 grunt
时未指定特定任务,则它 运行 是 default
任务,在这种情况下只有 运行 connect
和 watch
.
有两种修复方法:
- 只需在命令行上调用
grunt browserify
- 将默认任务更改为:
['browserify', 'connect', 'watch']