2016-05-24 4 views
0

私はNode.jsウェブサイトで作業しています。私はGruntを使用して、CSSファイルとJSファイルを連結して縮小しています。しかし、gruntコマンドを実行した後、私は、エラーメッセージが出ている:私は持っているだろう何がjQueryの連結なってきたものであろうと思った場合はGrunt concats JSファイル複数回

/*global module */ 
module.exports = function (grunt) { 
    "use strict"; 
    grunt.initConfig({ 
     // read in the project settings from the package.json file into the pkg property 
     pkg: grunt.file.readJSON("package.json"), 

     // Install only the bower packages that we need 
     bower: { 
      install: { 
       options: { 
        "targetDir": "./public/lib", 
        "copy": true, 
        "cleanup": true, 
        "install": true 
       } 
      } 
     }, 

     concat: { 
      css: { 
       src: ["public/lib/css/**/*.css", "public/css/cts.css"], 
       dest: "public/lib/dist/main.css" 
      }, 
      js: { 
       src: ["public/lib/**/jquery.js", "public/lib/**/*.js", "public/js/cts.js"], 
       dest: "public/lib/dist/main.js" 
      } 
     }, 

     cssmin: { 
      target: { 
       files: { 
        "public/lib/dist/main.min.css": "public/lib/dist/main.css" 
       } 
      } 
     }, 

     uglify : { 
      js: { 
       files: { 
        "public/lib/dist/main.min.js": "public/lib/dist/main.js" 
       } 
      } 
     }, 

     copy: { 
      files: { 
       expand: true, 
       flatten: true, 
       src: ["public/lib/fonts/**/*"], 
       dest: "public/lib/fonts/", 
       filter: "isFile" 
      } 
     } 
    }); 

    // Add all plugins that your project needs here 
    grunt.loadNpmTasks("grunt-bower-task"); 
    grunt.loadNpmTasks("grunt-contrib-concat"); 
    grunt.loadNpmTasks("grunt-contrib-copy"); 
    grunt.loadNpmTasks("grunt-contrib-cssmin"); 
    grunt.loadNpmTasks("grunt-contrib-uglify"); 
    grunt.loadNpmTasks("grunt-contrib-watch"); 

    // this would be run by typing "grunt test" on the command line 
    // the array should contains the names of the tasks to run 
    grunt.registerTask("test", []); 

    // define the default task that can be run just by typing "grunt" on the command line 
    // the array should contains the names of the tasks to run 
    grunt.registerTask("default", [ "bower", "concat", "cssmin", "uglify", "copy"]); 
    grunt.registerInitTask("install", ["bower"]); 
}; 

fullPage: Fullpage.js can only be initialized once and you are doing it multiple times!

は、ここに私のイサキファイルです何度も繰り返しますが、そうではありません。私が間違っていることを示唆していますか?

EDIT:ここに、concat.srcにリストされているすべてのサードパーティ製ライブラリを使用してアップグレードしたgruntファイルがあります。

/// <binding BeforeBuild='default' /> 
/*global module */ 
module.exports = function (grunt) { 
    "use strict"; 
    grunt.initConfig({ 
     // read in the project settings from the package.json file into the pkg property 
     pkg: grunt.file.readJSON("package.json"), 

     // Install only the bower packages that we need 
     bower: { 
      install: { 
       options: { 
        "targetDir": "./public/lib", 
        "copy": true, 
        "cleanup": true, 
        "install": true 
       } 
      } 
     }, 

     concat: { 
      css: { 
       src: ["public/lib/css/**/*.css", "public/css/cts.css"], 
       dest: "public/lib/dist/main.css" 
      }, 
      js: { 
       src: [ 
        "public/lib/js/jquery/jquery.js", 
        "public/lib/js/bootstrap/bootstrap.js", 
        "public/lib/js/fullpage.js/jquery.fullpage.js", 
        "public/lib/js/jquery-easing-original/jquery.easing.js", 
        "public/lib/js/slimscroll/jquery.slimscroll.js", 
        "public/lib/js/wow/wow.js", 
        "public/js/cts.js" 
        ], 
       dest: "public/lib/dist/main.js" 
      } 
     }, 

     cssmin: { 
      target: { 
       files: { 
        "public/lib/dist/main.min.css": "public/lib/dist/main.css" 
       } 
      } 
     }, 

     uglify : { 
      js: { 
       files: { 
        "public/lib/dist/main.min.js": "public/lib/dist/main.js" 
       } 
      } 
     }, 

     copy: { 
      files: { 
       expand: true, 
       flatten: true, 
       src: ["public/lib/fonts/**/*"], 
       dest: "public/lib/fonts/", 
       filter: "isFile" 
      } 
     } 
    }); 

    // Add all plugins that your project needs here 
    grunt.loadNpmTasks("grunt-bower-task"); 
    grunt.loadNpmTasks("grunt-contrib-concat"); 
    grunt.loadNpmTasks("grunt-contrib-copy"); 
    grunt.loadNpmTasks("grunt-contrib-cssmin"); 
    grunt.loadNpmTasks("grunt-contrib-uglify"); 
    grunt.loadNpmTasks("grunt-contrib-watch"); 

    // this would be run by typing "grunt test" on the command line 
    // the array should contains the names of the tasks to run 
    grunt.registerTask("test", []); 

    // define the default task that can be run just by typing "grunt" on the command line 
    // the array should contains the names of the tasks to run 
    grunt.registerTask("default", [ "bower", "concat", "cssmin", "uglify", "copy"]); 
    grunt.registerTask("combine", [ "concat", "cssmin", "uglify", "copy"]); 
    grunt.registerInitTask("install", ["bower"]); 
}; 
+0

jqueryパスにワイルドカードが含まれている特定の理由はありますか?不要です。 – theaccordance

+0

このプロジェクトには複数の人がおり、入れ子構造が変わる可能性があります。ワイルドカードは、ファイルが 'public/lib /'の下にある限り、これが確実に動作するようにします。 – tylerbhughes

答えて

1

あなたの問題はconcate.js.src

src: ["public/lib/**/jquery.js", "public/lib/**/*.js", "public/js/cts.js"] 

であるように思わこれは、SRCに言及したパスのうち、一般的ないくつかのファイルがあるかもしれませんが、あなたのファイルが複数回追加されます。

jqueryのようなすべてのベンダーファイルをパブリックディレクトリから移動し、別のベンダーファイル(ベンダーなど)に置いてください。あなたは今、これらの二つのパスの間には共通のファイルが存在しない見たよう

あなたのSRCは、

src: ["vendor/**/*.js", "public/**/*.js"] 

ようになるはずです。

また、常に、アプリディレクトリ外の第三者コードを兄弟フォルダとして持ち、内部にはないようにすることをお勧めします。

EDIT:

ああ!あなたの問題は何か分かります。まず、他のベンダーのファイルの中でjqueryを使いたいとします。

public/lib/**/jquery.jspublic/lib/**/*.jsが一緒にファイルを2回追加している可能性があります。

この

src: ["public/lib/jquery/jquery.js", "public/lib/**/*.js", "!public/lib/jquery/jquery.js", public/js/cts.js"] 

最初public/lib/jquery/jquery.jsをjqueryのフルパスを入れて試してみて、その後、jqueryのを防ぐべき!public/lib/jquery/jquery.jshttp://gruntjs.com/configuring-tasks#globbing-patterns

ここから上記パターンを得たpublic/lib/**/*.js

の一部として再度追加さそれでも解決しない場合は、src配列内のすべてのパスを個別に追加することもできます。 requirejsの設定をしている場合、そこからパスをコピーするだけです。jqueryは将来あなたが直面する唯一の依存関係の問題ではないかもしれません。

+0

'public/lib/**'の中のすべてのファイルは単なるベンダーファイルです。だから私はそれらをlibフォルダに持っています。私の現在のsrc設定はあなたのものと同じくらい簡単ではありません。なぜなら、それらのファイルの1つがBootstrap JSファイルであり、jQueryが最初に追加されなければならないからです。 – tylerbhughes

+0

@RandomlyKnighted:わかりました。私は答えを編集しました。それが – shinobi

+0

を助けるかどうかは、jQueryと私の他のベンダーファイルの1つが定義されていないと言ってしまったのかどうかを見てください。私はすべてのパスを個別に追加して行きました。ベンダーファイルが複数回初期化されています。 – tylerbhughes

関連する問題