Skip to content

Instantly share code, notes, and snippets.

@syuji-higa
Last active December 26, 2021 06:32
Show Gist options
  • Save syuji-higa/cde49aae4945695a737905bd22cdc946 to your computer and use it in GitHub Desktop.
Save syuji-higa/cde49aae4945695a737905bd22cdc946 to your computer and use it in GitHub Desktop.
Nuxt.js - env module for axios
API_BASE_URL=http://localhost:8000
API_BASE_URL=https://example.com/api/v1
API_BASE_URL=https://staging.example.com/api/v1
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
},
}
{
"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"
}
}
@Pistil-Studio
Copy link

nice thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment