如何使用 https 运行 Vue.js dev serve? [英] How to run Vue.js dev serve with https?
问题描述
我正在使用 Vue-cli 创建带有 webpack 模板的 vue 项目.如何在开发中使用 https 运行它:npm run dev
?
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 dev serve?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!