Reputation: 489
I have some problems with grunt because it seems to do more things than I want it to do. I have two folders with two local grunts in them, but when I launch it locally from one folder, it does also do what the "other" grunt, in the other folder, should do. I have an index.html file in each folder with different code, leading to different JavaScript (.js) files, but grunt executes both of them. (First the one in the other folder, and then the one in the folder from where I launch it.)
I am not publishing any code at the moment because I feel that the question should be relatively code-independent, but if anyone thinks it is necessary to answer the issue, I'll do.
Do you think the issue originates from the global grunt that I installed before the local grunts? (I.e. it searches for all the files and executes the instructions?)
Any hints, ideas, suggestions? Thank you.
EDIT: a better description of my file structure. On the Desktop I have two folders (projects) with two local grunts installed. In the first project, index.html is:
<html>
<head><title>Testing grunt</title></head>
<body>
<script src="scripts/app.js"></script>
<h1>It works!</h1>
</body>
</html>
Here, app.js calls another .js file that fires up an alert message.
This works ok as a test. But in the second project (folder), this being in the Desktop too, index.html is:
<!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>
Leading to a different app.js file that is a little sample game that I did using the phaser.js library.
The problem is that when I launch grunt from the "game" folder, both the "Hello!!!" and the alerts from the first folder show up, instead of the game that should be launched by the grunt that is in the game folder. No game starts, but this is another problem. First, I'd need to get rid of the alert (i.e. the "other" index.html being launched)
Hope this helps in better understanding the problem / situation.
EDIT: Here is my 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']);
};
EDIT: Output of 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.
Upvotes: 0
Views: 501
Reputation: 28737
So, you are never actually running the browserify
task. When you run grunt
on the command line without specifying a specific task, then it runs the default
task, which in this case only runs connect
and watch
.
There are two ways to fix:
grunt browserify
on the command line['browserify', 'connect', 'watch']
Upvotes: 1