咕噜咕噜的问题

时间:2016-12-24 14:13:24

标签: javascript html node.js browser gruntjs

我对grunt有一些问题,因为它似乎做了比我想做的更多的事情。我有两个文件夹,其中包含两个本地grunt,但是当我从一个文件夹本地启动它时,它也会执行另一个文件夹中的“其他”grunt应该执行的操作。我在每个文件夹中都有一个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库做的一个小样本游戏。

问题是,当我从“游戏”文件夹中启动grunt时,“Hello !!!”并显示来自第一个文件夹的警报,而不是应该由游戏文件夹中的grunt启动的游戏。没有游戏开始,但这是另一个问题。首先,我需要摆脱警报(即“其他”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.

1 个答案:

答案 0 :(得分:1)

因此,您实际上从未运行browserify任务。当您在命令行上运行grunt而未指定特定任务时,它将运行default任务,在这种情况下,该任务仅运行connectwatch

有两种方法可以解决:

  1. 只需在命令行上调用grunt browserify
  2. 将默认任务更改为:['browserify', 'connect', 'watch']
相关问题