1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Gruntで環境ごとに設定を変える

Last updated at Posted at 2016-05-02

はじめに

この記事では、環境によりGruntfile.jsの設定を変える方法を説明します。

grunt.mergeを使いましょう

以下のように共通設定はgrunt.initConfig、環境ごとに異なる設定はgrunt.mergeを使いましょう。ちなみにですが、

module.exports = function(grunt) {
    
    grunt.initConfig({
            // 全環境での共通設定はここに書く
        });

    // ここから下は、環境ごとの設定を書いていく
    // サンプルコードではenvに環境名が入っているとする
    // 環境名に入るのは、test、productionを想定
    
        if (env === 'test') {
        grunt.merge({
          // テスト環境の設定
        });
    }

        if (env === 'production') {
        grunt.merge({
          // 本番環境の設定
        });
    }


grunt.merge
http://gruntjs.com/api/grunt.config#grunt.config.merge

おわりに

今まで環境ごとにGruntfile.jsを用意していましたが、これからは1つのファイルで大丈夫になりました。手前味噌ですが、自作ゲームでこれを試してみました。

プロジェクト全体のコードはここです。
https://github.com/kaidouji85/gbraver/tree/e732f88190669adb31a86ebda6cb1cab58667af0

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?