17

package.json の「main」プロパティを使用して、「dist」または展開に必要なファイルだけをコピーできることをどこかで読んだことがあります。それには単調な仕事があると思っていましたが、私を助けたり教えたりするものは何もありません。node_modules の下にすべてをコピーするようになりましたが、ライブラリのサンプル コードなどを配布する必要はありません。

grunt-contrib-copy を適切に使用して、できれば config オブジェクトの標準 pkg オブジェクト (解析された package.json ファイル) から node_module 依存関係からファイルをコピーする方法についての grunt タスクまたは指示はありますか?

4

2 に答える 2

12

package.json doesn't contain enough information for you to know what to include. You would have to parse out all the require statements, but even then there are cases you can't detect, like a module loading resources, etc.

The right way to do this is for package authors to ignore the files that isn't needed using a .npmignore file or even better, use the files property in package.json to explicitly define what files should be included in the package.

Unfortunately though, most package authors are lazy and don't bother with any of this...

I would encourage you to open PRs on the modules in question with the files property.

于 2013-08-15T09:55:10.903 に答える
11

あなたはできる:

1) コピー タスクを使用して、関連する各ファイルを dest ディレクトリにコピーします。

copy:
  js:
    files: [
      { 
         expand: true, 
         cwd: 'node_modules/jquery', 
         src: 'jquery.min.js', 
         dest: 'www/js' 
      },
      { 
         expand: true, 
         cwd: 'node_modules/jquery-mobile-bower/js', 
         src: 'jquery.mobile-*.min.js', 
         dest: 'www/js' 
      }
    ]

jquery.min.js と jquery.mobile-xyzmin.js は両方とも www/js ディレクトリにコピーされます。

2) concat タスクを使用して、すべてのファイルを単一の dest ファイルに連結します (一意の javascript / stylesheets ファイルを生成するのに役立ちます)。

concat:
  options:
    separator: ';'
  js:
    dest: 'www/js/lib.js'
    src: [
      'node_modules/jquery/jquery.min.js',
      'node_modules/jquery-mobile-bower/js/jquery.mobile-*.min.js'
    ]

jquery.min.js と jquery.mobile-xyzmin.js は、セミコロンで区切られた単一の www/js/lib.js ファイルにマージされます。

于 2013-10-05T04:24:27.417 に答える