vue.js - 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
...?
解决方案
你可以使用一些条件,比如
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/
推荐阅读
- java - JaVers 的 MongoDB 文档版本更新问题
- spring-boot - 从 swagger codegen 插件生成的界面中的 Produces 属性有一个额外的值“result”
- angular - 如果在页面刷新一段时间后打开该组件,ngx-extended-pdf-viewer 不会加载 pdf
- javascript - 来自 Vue.js 组件的 Img 元素未渲染到 Laravel 生产环境中
- graphql - 有没有办法为两个或多个 GraphQL 服务生成聚合的 schema.json?
- c++ - 是否可以使用 gcc/g++ 从 Windows 编译到 Linux?
- three.js - 如何在 Autodesk Forge 中对缓冲区几何对象进行分组
- reactjs - 使用功能组件反应条件重新渲染不起作用
- python - 如何在我的 python beautifulsoup 代码片段中获取前 10 个表数据
- java - 从 Java 运行 .vbs 文件