![](/img/trans.png)
[英]How can i solve "Error: \src\main.ts is missing from the TypeScript compilation."
[英]how to test a setting in vue.config.js from src\main.ts?
当您导航到该页面时,我正在修改我的 vue 应用程序以添加代码以强制从 http 重定向到 https。
(是的,知道在网络服务器中这样做更好,腰带和吊带)
if (location.protocol !== 'https:') {
console.info('redirecting!')
location.replace(`https:${location.href.substring(location.protocol.length)}`)
} else {
console.info('not redirecting...')
}
但如果在 vue.config.js 中,我想跳过该代码
devServer: {
https: true,
如果该设置更改为 false。
我怎样才能做到这一点?
Vue 编译的应用程序无法感知 vue.config.js 的内容,反之亦然。 这两部分都可以依赖于带有VUE_
前缀的公共环境变量,可以从 .env 文件或其他地方提供:
devServer: {
https: process.env.VUE_HTTPS === '1',
...
和
if (process.env.VUE_HTTPS === '1' && location.protocol !== 'https:') {
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.