LoginSignup
0
0

More than 1 year has passed since last update.

Nuxtでビルド時に環境変数をセットする

Last updated at Posted at 2021-12-21

はじめに

基本的には.envファイル等使うかと思いますが、この記事ではビルド時にセットする方法になります。

実装

Nuxtでは環境変数の頭にNUXT_ENVを付与する必要があります。
https://nuxtjs.org/docs/configuration-glossary/configuration-env/#automatic-injection-of-environment-variables

下記はStorybookのビルドの時だけセットするという例になります。

package.json
...
"scripts": {
  "storybook": "set NUXT_ENV_IS_STORYBOOK=true && yarn nuxt storybook"
}
...
nuxt.config.js
...
process.env.NUXT_ENV_IS_STORYBOOK // true
...

おわりに

備忘録的な内容なので薄いですが、何かあればコメントいただけると幸いです。

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