LoginSignup
5
4

More than 5 years have passed since last update.

Closure Compiler で定数置換

Posted at

Closure Compiler定数の置換が便利だったのでメモ。

/** @define {string} */
var HOGE = 'hoge';

こんなソースを

java -jar compiler.jar --define "HOGE='moge'" --js src.js

と実行すると

var HOGE="moge";

定数の値を上書きして出力してくれる。
API KEY とかを環境で切り分ける時に便利かもしれない。

ついでに Grunt で使う時は

config =  {
    js: src.js,
    options: {
        define: [
            "HOGE=\\'moge\\'"
        ]
    }
};

と指定する。

5
4
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
5
4