8
3

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 3 years have passed since last update.

Makefileでコマンド管理

Last updated at Posted at 2022-04-07

1.はじめに

みなさん、Makefileをご存知でしょうか?
僕は独学で勉強していた際に、Makefileという便利なファイルを知りました。
簡単にいうと、(プロジェクトごとに)コマンドにエイリアスをつけて、呼び出せます!
是非、広まってほしいと思い、記事にすることにしました。

2. Makefileとは

元々はC言語で使われていたファイルで、依存関係の管理、インストールなどのルールを記述しておくためのファイルだそうですが、
その性質を利用して、コマンドにエイリアスをつけて、呼び出せます。

以下は実際に僕が使っているMakfileになります(プロジェクト直下に置いてます)。

.PHONY: up lint format install uninstall

up:
	docker-compose up

lint:
	docker-compose run --rm next npm run lint:fix

format:
	docker-compose run --rm next npm run format

install:
	docker-compose run --rm next npm install ${P}

uninstall:
	docker-compose run --rm next npm uninstall ${P}

これを呼び出すときは

$ make up

でdocker-compose upが実行されます。

コマンドの内容を動的に変えたい場合は、
make installで説明すると

$ make install P=@mui/material

と渡すことができます。

3.最後に

いかがでしょうか?
Makefileにプロジェクト毎によく使われるコマンドを記載しておけば、
ターミナルでの作業が効率化でき、
別の人がプロジェクトに参画した際にも、コマンドのマニュアルになるので、
いいことづくめだと思います!
もっと広まってほしい、、、

8
3
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
8
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?