如何通过https运行Vue.js开发服务? [英] How to run Vue.js dev serve with https?
问题描述
我正在使用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屋!