0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Shopify CLI を使って VS Code でテーマ開発する方法

Last updated at Posted at 2025-03-01

はじめに

Shopifyのテーマ開発は、旧「Theme Kit」から「Shopify CLI」に完全移行されました。
この記事では、最新のCLI環境(npm版)を使用して、Shopifyストアのテーマをローカルで開発・プレビュー・反映するまでの手順を解説します。


1. 開発環境の前提条件

必要なもの 内容
Node.js v18以上(LTS推奨)
Shopifyアカウント テーマ編集権限のあるユーザー
VS Code コードエディタ(無料)

2. Shopify CLIのインストール

Shopify CLIは現在npm経由で提供されています。
Homebrew版は廃止されています。

npm install -g @shopify/cli @shopify/theme

Node.jsのバージョンが古い場合は、以下で更新します。

node -v
nvm install --lts
nvm use --lts

3. Shopifyにログイン

CLIからShopifyにログインします。

shopify auth login

ブラウザが開いたら、対象ストア(例:your-store.myshopify.com)にアクセスできるアカウントでログインします。
ログインが成功すると、ターミナルに次のような表示が出ます。

✔ Logged in.
✔ Current account: yourname@example.com

4. 対象ストアの設定

プロジェクト直下に、ストア情報を紐づける設定ファイルを作成します。

printf "shop: your-store.myshopify.com\n" > .shopify-cli.yml

これにより、以降のコマンドで毎回 --store を指定する必要がなくなります。


5. テーマの取得

既存のテーマをローカルにダウンロードします。

shopify theme pull -s your-store.myshopify.com

ダウンロードが完了すると、/templates/sections など、Shopifyテーマの基本構造がローカルに展開されます。


6. ローカル開発(リアルタイムプレビュー)

テーマを編集しながらリアルタイムでプレビューします。

shopify theme dev

出力例:

Preview your theme:
→ http://127.0.0.1:9292

Shareable preview:
→ https://your-store.myshopify.com/?preview_theme_id=XXXXXX

この状態でVS Codeなどでテーマを編集すると、変更が自動的にShopifyのプレビュー環境に反映されます。


7. テーマの反映(アップロード)

ローカルで編集した内容をShopify本番環境に反映します。

shopify theme push

CLIが変更内容を確認し、アップロード前に差分を表示します。


8. よくあるエラーと対処方法

エラー内容 原因 対処法
A store is required ストア未指定 .shopify-cli.ymlshop: を設定
401: Service is not valid for authentication 認証セッション切れ shopify auth logout --allshopify auth login
You are not authorized to use the CLI 権限不足 管理画面で「テーマ編集」権限を付与

9. VS Codeでのおすすめ拡張機能

拡張機能名 説明 インストール
Shopify Liquid Preview Liquidテンプレートをプレビュー表示 https://marketplace.visualstudio.com/items?itemName=Shopify.theme-check-vscode
Shopify Liquid Snippets Liquid構文のスニペット補完 https://marketplace.visualstudio.com/items?itemName=killalau.vscode-liquid-snippets

10. コマンドまとめ

目的 コマンド
ログイン shopify auth login
ストア設定 printf "shop: your-store.myshopify.com" > .shopify-cli.yml
テーマ取得 shopify theme pull
ローカル開発 shopify theme dev
本番反映 shopify theme push
ログアウト shopify auth logout --all

まとめ

  • Shopify CLIはnpm経由でインストールする(Homebrew版は非推奨)
  • .shopify-cli.yml でストアを紐づけておくと便利
  • shopify theme dev でローカル開発、shopify theme push で反映
  • VS Code拡張を使うとLiquid開発が効率的になる
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?