在 https 上运行 svelte dev

mic*_*oo8 6 rollupjs svelte

我正在尝试使用 svelte 使用它的模板(https://github.com/sveltejs/template/)作为起点。

\n

我想使用https://github.com/nimiq/qr-scanner扫描二维码,但在我的电脑上,我没有网络摄像头,而且我的手机不想启动 qrScanner,因为该页面不是\ 不通过 h​​ttps 提供服务。

\n

当我跑步时npm run dev我得到:

\n
  Your application is ready~! \n\n  - Local:      http://0.0.0.0:5000\n  - Network:    http://192.168.1.13:5000\n\n\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80 LOGS \xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\n
Run Code Online (Sandbox Code Playgroud)\n

我的 rollup.config.js:

\n
  Your application is ready~! \n\n  - Local:      http://0.0.0.0:5000\n  - Network:    http://192.168.1.13:5000\n\n\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80 LOGS \xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\n
Run Code Online (Sandbox Code Playgroud)\n

和包 json:

\n
import svelte from "rollup-plugin-svelte";\nimport resolve from "@rollup/plugin-node-resolve";\nimport commonjs from "@rollup/plugin-commonjs";\nimport livereload from "rollup-plugin-livereload";\nimport { terser } from "rollup-plugin-terser";\nimport { string } from "rollup-plugin-string";\n\nconst production = !process.env.ROLLUP_WATCH;\n\nfunction serve() {\n    let server;\n\n    function toExit() {\n        if (server) server.kill(0);\n    }\n\n    return {\n        writeBundle() {\n            if (server) return;\n            server = require("child_process").spawn(\n                "npm",\n                ["run", "start", "--", "--dev"],\n                {\n                    stdio: ["ignore", "inherit", "inherit"],\n                    shell: true,\n                }\n            );\n\n            process.on("SIGTERM", toExit);\n            process.on("exit", toExit);\n        },\n    };\n}\n\nexport default {\n    input: "src/main.js",\n    output: {\n        sourcemap: true,\n        format: "iife",\n        name: "app",\n        file: "public/build/bundle.js",\n    },\n    plugins: [\n        svelte({\n            // enable run-time checks when not in production\n            dev: !production,\n            // we\'ll extract any component CSS out into\n            // a separate file - better for performance\n            css: (css) => {\n                css.write("public/build/bundle.css");\n            },\n        }),\n        string({\n            include: "node_modules/qr-scanner/qr-scanner-worker.min.js",\n        }),\n\n        // If you have external dependencies installed from\n        // npm, you\'ll most likely need these plugins. In\n        // some cases you\'ll need additional configuration -\n        // consult the documentation for details:\n        // https://github.com/rollup/plugins/tree/master/packages/commonjs\n        resolve({\n            browser: true,\n            dedupe: ["svelte"],\n        }),\n        commonjs(),\n\n        // In dev mode, call `npm run start` once\n        // the bundle has been generated\n        !production && serve(),\n\n        // Watch the `public` directory and refresh the\n        // browser on changes when not in production\n        !production && livereload("public"),\n\n        // If we\'re building for production (npm run build\n        // instead of npm run dev), minify\n        production && terser(),\n    ],\n    watch: {\n        clearScreen: false,\n    },\n};\n
Run Code Online (Sandbox Code Playgroud)\n

mic*_*oo8 8

所以我想通了,svetle-template 是与 Sirv-cli 一起提供的。

它有参数:--http2 --cert cert.pem --key key.pem