如何通过https运行Vue.js开发服务? [英] How to run Vue.js dev serve with https?

查看:579
本文介绍了如何通过https运行Vue.js开发服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Vue-cli通过Webpack模板创建vue项目.在开发中如何使用npm run dev在https中运行它?

I'm using Vue-cli to create vue project with webpack template. how to run it with https in development using: npm run dev?

推荐答案

Webpack模板使用 express 作为开发服务器.因此,只需替换

Webpack template uses express as the server for development. So just replace

var server = app.listen(port)

build/dev-server.js

var https = require('https');
var fs = require('fs');
var options = {
  key: fs.readFileSync('/* replace me with key file's location */'),
  cert: fs.readFileSync('/* replace me with cert file's location */'))
};
var server = https.createServer(options, app).listen(port);

请注意,在webpack模板中,http://localhost:8080将通过使用 opn 模块.因此,为方便起见,最好将var uri = 'http://localhost:' + port替换为var uri = 'https://localhost:' + port.

Please note that in webpack template, http://localhost:8080 will be automatically opened in your browser by using opn module. So you'd better replace var uri = 'http://localhost:' + port with var uri = 'https://localhost:' + port for convenience.

这篇关于如何通过https运行Vue.js开发服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆