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?

More than 1 year has passed since last update.

Nuxt.jsの新規プロジェクト作成における「対話型コマンド」をDockerfileで自動入力する

Posted at

概要

Nuxt.jsにおいて新規プロジェクトを作成するnpm init nuxt-app {ディレクトリ名}をDockerfileで実施するのに躓いてしまったので、メモを兼ねて記載。

やりたいこと

Nuxt.jsの新規プロジェクト作成における、「コマンドライン上の質問(プロジェクト名や使用言語など)」を自動で入力し、Dockerイメージをbuildするタイミングで新規プロジェクトも作っちゃいたい。

解決策

質問に対する回答を入力するためのjsonテキストを作成しておき、--answerオプションを付けてコマンドを実行する。

Dockerfile
FROM node:14
USER node
WORKDIR /home/node
RUN npm install create-nuxt-app
RUN npm init nuxt-app src --answers "{ \
  \"name\": \"kotonoha-app\", \
  \"language\": \"ts\", \
  \"pm\": \"npm\", \
  \"ui\": \"balm-ui\", \
  \"features\": \"axios\", \
  \"linter\": \"eslint\", \
  \"test\"  : \"none\", \
  \"mode\"  : \"universal\", \
  \"target\"  : \"server\", \
  \"devTools\": \"dependabot\", \
  \"ci\": \"github-actions\", \
  \"gitUsername\": \"itezora-nonoha\", \
  \"vcs\": \"git\" }"

対話入力時の後ろの方の質問は、「前の質問に対する回答によっては出現しない」ことがある。
しかし、--answerをオプションを使用する際のjsonについては「問われない選択項目に対する回答」も入れておかないとコマンド実行に失敗してしまうため注意。上記例だとci項目などは対話入力においては不要

create-nuxt-appのヘルプ内容

image.png

参考リンク

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?