Last active
December 26, 2021 06:32
-
-
Save syuji-higa/cde49aae4945695a737905bd22cdc946 to your computer and use it in GitHub Desktop.
Nuxt.js - env module for axios
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
API_BASE_URL=http://localhost:8000 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
API_BASE_URL=https://example.com/api/v1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
API_BASE_URL=https://staging.example.com/api/v1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { resolve } from 'path' | |
const env = process.env.NODE_ENV | |
const envFile = `.env.${env}` | |
require('dotenv').config({ path: resolve(__dirname, envFile) }) | |
const nuxtConfig = { | |
axios: { | |
baseURL: process.env.API_BASE_URL | |
}, | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"scripts": { | |
"dev": "cross-env NODE_ENV=develop nuxt", | |
"generate:staging": "cross-env NODE_ENV=staging nuxt generate", | |
"generate": "cross-env NODE_ENV=production nuxt generate" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice thx