npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

generator-grunt-share

v1.0.3

Published

gruntfileを分割できるようになるgruntプロジェクトテンプレート

Readme

grunt-share

About

Sample

Setup

  1. Node.jsをインストール

  2. sudo npm install -g yo grunt-cli bower

  3. プロジェクトテンプレートをダウンロード sudo npm install https://github.com/dummy/generator-grunt-share -g

  4. プロジェクトテンプレートをインストール cd インストールしたいディレクトリ
    yo grunt-share

Gruntfiles

Gruntfile.jsは基本的に直接編集せず、
/gruntfilesにあるtemplate_grunt.jsをコピペして好きな名前にリネームし、 自分専用のgruntfileとします。

通常のGruntfile.jsの基本構成は以下のようになりますが、
(参考)Gruntで快適な環境を整備したい!【タスク記述編】

 module.exports = function(grunt){
 
   ’use strict’;
 
   grunt.initConfig({
     // package.jsonに設定されている内容を取得
     // バージョンや名称などの情報を外部ファイルで共通化できる
     pkg: grunt.file.readJSON(“package.json”),
 
     // タスクの設定
     タスク名:{
       // タスクの対象となるファイルのパスや出力先等の設定
     }
   });
 
   // プラグインの読み込み
   grunt.loadNpmTasks(“使用するプラグイン名”);
 
   // タスクに名前をつける
   // ”default” はgruntコマンドを入力した際に行うデフォルトのタスク
   grunt.registerTask(“default”, ["タスク名"]);
 
 };  

本テンプレート/gruntfiles/のgruntfileはこうなります。

 module.exports.extendGrantTask = function(grunt){
 
   ’use strict’;
 
   grunt.extendConfig({

     // タスクの設定
     タスク名:{
       // タスクの対象となるファイルのパスや出力先等の設定
     }
   });
 
   // プラグインの読み込み
   grunt.loadNpmTasks(“使用するプラグイン名”);
 
   // 共有タスクを登録する
   return {
    "common_before"   : ["タスク名"],
    "deploy"      : ["タスク名"],
    "release"       : ["タスク名"]
   };
 
 };  

gruntのチュートリアルサイトなどをみる時は以下を置き換えて考えてください。

  • module.exportsmodule.exports.extendGrantTask
  • grunt.initConfiggrunt.extendConfig
  • grunt.registerTaskreturn {}

returnオブジェクトで以下タスク配列を記述することで共有タスクとして登録されます

  • common_before
    deployreleaseそれぞれの前に(releaseの場合コピー前に)実行される共通タスク
  • deploy
    deployビルド専用タスク
  • release
    releaseビルド専用タスク

共有のため必ず任意のサブタスク名をつけるようにしてください。
NG

uglify: {
    src: [“src/js/hoge1.js“, “src/js/hoge2.js“]
    dest: “deploy/js/hoge.min.js”
   },
   

['copy','concat','uglify']

OK

uglify: {
      hoge: {
         src: [“src/js/hoge1.js“, “src/js/hoge2.js“]
         dest: “deploy/js/hoge.min.js”
      }
   },
   

['copy:hoge','concat:hoge']


grunt-contrib-〜
で始まるプラグインはテンプレートに初めから組み込まれているので
grunt.loadNpmTasksを呼ぶ必要はありません。

それ以外は基本的に通常のGruntfile.jsと同じように使えます。
とりあえず個人個人で色々と試してみるべきではないかと思います。

Directory構成

/
|-- .gitignore
|-- package.json - 設定。devDependencyを基にnode_modulesに依存ファイルをインストールします
|-- node_modules - grunt含め外部nodeモジュールファイルの格納場所
|-- release - リリース(release)ビルドの書き出し先
|-- README.md - 本ドキュメント
|-- Gruntfile.js - gruntfiles内のファイルを読み込みまとめて制御する。共有タスクを追記する。
|-- libs - ライブラリなど
|-- src - コンパイルが必要な言語、結合前JSなど
|-- deploy - 開発(deploy)ビルドの書き出し先
`-- gruntfiles - 個々別々のgruntfile置き場
    `-- template_grunt.js - 個人用gruntfileテンプレート。コピーして使う

ビルド

deploy版(開発版)書き出し

  • ターミナル cd プロジェクトディレクトリ + grunt deploy
  • プロジェクトディレクトリ選択 +
    【コンテキストメニューコマンド】Gruntーdeploy版を書き出し

実行順序

  1. common_before タスク(deploy、release共通)

deployビルド

  1. deployタスク

deployビルド


release版(リリース版)書き出し

  • ターミナル cd プロジェクトディレクトリ + grunt release
  • プロジェクトディレクトリ選択 +
    【コンテキストメニューコマンド】Gruntーrelease版を書き出し

実行順序

  1. common_before タスク(deploy、release共通)

releaseビルド

  1. copyタスク(全ファイルをdeploy→releaseにコピー)

releaseビルド2

  1. releaseタスク

releaseビルド

自分のgruntfileだけビルドしたい

拡張子除くgruntファイル名を引数に渡す
grunt deploy:your_gruntfile_name
grunt release:your_gruntfile_name

Git連携

.gitignore

gitignoreファイルは記述したファイルをgitの管理から除外するGit設定ファイルです。
以下のように指定しています。

.*
components/
bower.json
node_modules/
release/
!.gitignore

node_modules/が除外されているため、初めにgitからデータを取ってきた時には 依存ファイルをインストールする必要があります。(package.jsonのdevDependenciesを基にnode_modules/にインストールされます)
インストールしたいディレクトリを選択して
【コンテキストメニューコマンド】
Grunt-依存ファイルをインストール
または、ターミナルを開いて
cd インストールしたいディレクトリ
grunt install

package.jsondevDependenciesを基にnode_modules/にインストールされます。

Tips

直書きはどこでするか?

deploy フォルダで。

独自にnode_modulesに追加したいモジュールがある

ターミナルgrunt install 追加したいモジュール -save-dev
後ろに-save-devをつけるとpackage.jsondevDependenciesにモジュール名が記録され、 Gitを通じて共有されるので忘れないように。

ファイルの更新を監視して自動ビルドさせたい

watch:サブタスク名タスクにdeploy releaseを指定。

watch: {
     hoge: {
        // 変更を監視するファイルを指定
         files: ["deploy/js/"],
         // 変更されたらどのタスクを実行するか
         tasks: ["deploy:your_gruntfile_name"]
      }
   },

開発版とリリース版で処理をわけて書くのが大変

common_beforeタスクのみを使う