首页 > 解决方案 > nuxt.js Configuring Localhost https server (but not in production)

问题描述

I have the following server configuration setup for my nuxt.js project:

import path from 'path'
import fs from 'fs'

export default {
  ...
  
  server: {
    https: {
      key: fs.readFileSync(path.resolve(__dirname, 'server.key')),
      cert: fs.readFileSync(path.resolve(__dirname, 'server.crt'))
    }
  }
  
  ...
}

This all works great in local development - but we deploy to Netlify. And it causes issues when deployed in production.

So, I was wondering, what is the "trick" to turning certain configurations on and off in production inside nuxt.config.js...?

标签: vue.jsnuxt.js

解决方案


你可以使用一些条件,比如

baseURL: process.env.NODE_ENV === 'production' ? 'https://nuxtjs.org' : 'https://dev.nuxtjs.org'

或 env 变量,.env在您的 Netlify 仪表板中具有不同的值。

这是一篇关于运行时环境变量的有趣文章:https ://nuxtjs.org/blog/moving-from-nuxtjs-dotenv-to-runtime-config/

这里是关于 env 变量的官方文档:https ://nuxtjs.org/docs/2.x/configuration-glossary/configuration-env/


推荐阅读