gpt4 book ai didi

svelte - 在 https 上运行 svelte dev

转载 作者:行者123 更新时间:2023-12-04 02:29:50 24 4
gpt4 key购买 nike

我正在尝试使用 svelte 的模板( https://github.com/sveltejs/template/ )作为起点。
我想用 https://github.com/nimiq/qr-scanner 扫描二维码,但在我的电脑上,我没有网络摄像头,而且我的手机不想启动 qrScanner,因为该页面不是从 https 提供的。
当我运行时 npm run dev我得到:

  Your application is ready~! 🚀

- Local: http://0.0.0.0:5000
- Network: http://192.168.1.13:5000

────────────────── LOGS ──────────────────
我的 rollup.config.js:
import svelte from "rollup-plugin-svelte";
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import livereload from "rollup-plugin-livereload";
import { terser } from "rollup-plugin-terser";
import { string } from "rollup-plugin-string";

const production = !process.env.ROLLUP_WATCH;

function serve() {
let server;

function toExit() {
if (server) server.kill(0);
}

return {
writeBundle() {
if (server) return;
server = require("child_process").spawn(
"npm",
["run", "start", "--", "--dev"],
{
stdio: ["ignore", "inherit", "inherit"],
shell: true,
}
);

process.on("SIGTERM", toExit);
process.on("exit", toExit);
},
};
}

export default {
input: "src/main.js",
output: {
sourcemap: true,
format: "iife",
name: "app",
file: "public/build/bundle.js",
},
plugins: [
svelte({
// enable run-time checks when not in production
dev: !production,
// we'll extract any component CSS out into
// a separate file - better for performance
css: (css) => {
css.write("public/build/bundle.css");
},
}),
string({
include: "node_modules/qr-scanner/qr-scanner-worker.min.js",
}),

// If you have external dependencies installed from
// npm, you'll most likely need these plugins. In
// some cases you'll need additional configuration -
// consult the documentation for details:
// https://github.com/rollup/plugins/tree/master/packages/commonjs
resolve({
browser: true,
dedupe: ["svelte"],
}),
commonjs(),

// In dev mode, call `npm run start` once
// the bundle has been generated
!production && serve(),

// Watch the `public` directory and refresh the
// browser on changes when not in production
!production && livereload("public"),

// If we're building for production (npm run build
// instead of npm run dev), minify
production && terser(),
],
watch: {
clearScreen: false,
},
};
并打包json:
{
"name": "myapp",
"version": "0.0.1",
"scripts": {
"build": "rollup -c",
"dev": "rollup -c -w",
"start": "HTTPS=true sirv public --single --host"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^14.0.0",
"@rollup/plugin-node-resolve": "^8.0.0",
"rollup": "^2.33.2",
"rollup-plugin-livereload": "^1.0.0",
"rollup-plugin-string": "^3.0.0",
"rollup-plugin-svelte": "^6.1.1",
"rollup-plugin-terser": "^6.1.0",
"svelte": "^3.29.7"
},
"dependencies": {
"graphql": "^15.4.0",
"graphql-request": "^3.3.0",
"jshashes": "^1.0.8",
"page.js": "^4.13.3",
"qr-scanner": "^1.2.0",
"sirv-cli": "^1.0.8"
}
}

最佳答案

所以我想通了,svetle-template 与 sirv-cli 一起提供。
它有参数:--http2 --cert cert.pem --key key.pem

关于svelte - 在 https 上运行 svelte dev,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64931403/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com