Daydreamer-riri / vite-react-ssg

Static-site generation for React on Vite.
https://vite-react-ssg.netlify.app/
MIT License
125 stars 6 forks source link

feat: support https #4

Closed childrentime closed 1 year ago

childrentime commented 1 year ago

This is reproducible #2 , which might be due to the devcert package only supporting commonjs and not esm. I'm not very familiar with unbuild. Is there a way to convert it, or do I need to fork a version of the devcert package that supports esm?

netlify[bot] commented 1 year ago

Deploy Preview for vite-react-ssg ready!

Name Link
Latest commit 1168261f32c83e88ebca10835abb281b8a6a2c76
Latest deploy log https://app.netlify.com/sites/vite-react-ssg/deploys/653b598c961dcd00084aa79f
Deploy Preview https://deploy-preview-4--vite-react-ssg.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Daydreamer-riri commented 1 year ago

The current version actually has common js products, but the cli file executed by default is in esm format. I think I can add a common js cli file.

Daydreamer-riri commented 1 year ago

@childrentime Hi, You could write a similar script to replace '.mjs' with '.cjs'.

https://github.com/Daydreamer-riri/vite-react-ssg/blob/main/bin/vite-react-ssg.js

childrentime commented 1 year ago

I'll give it a try. I'll see if it can run normally under the CommonJS (cjs) format, and then figure out how to make it work properly with ECMAScript Modules (esm) as well.

childrentime commented 1 year ago

@Daydreamer-riri well. This can't work either. Because devcert use dynamic require and rollup can't handle it.

image

Anyway, if you use devcert in a normal vite project, it just works well.

I can't understand why __dirname appears in the ESM (ECMAScript Module) bundle result . this sucks

Daydreamer-riri commented 1 year ago

@Daydreamer-riri well. This can't work either. Because devcert use dynamic require and rollup can't handle it. image Anyway, if you use devcert in a normal vite project, it just works well.

I can't understand why __dirname appears in the ESM (ECMAScript Module) bundle result . this sucks

Can you provide a repository for me to debug this problem?

childrentime commented 1 year ago

@Daydreamer-riri You can directly check out this pr, and install deps.

Daydreamer-riri commented 1 year ago

OK, I will check this problem as soon as possible.

childrentime commented 1 year ago

I just found out that Rollup does not convert __dirname by default. This plugin is needed: https://www.npmjs.com/package/rollup-plugin-node-globals.

But this package might be a bit outdated. Also, I tried const devcert = require('devcert');, the output in CommonJS can run normally, but the output in ESM still doesn't work. The best approach might be to modify the source code and packaging method of the devcert package.

Daydreamer-riri commented 1 year ago

devcert uses __dirname in its code, so its code is not bindable and it needs to maintain its own directory structure. I think we can allow https configuration to make vite-react-ssg support https at development time and state that in the documentation.

Users can install devcert on their own and configure it in vite.config.js.

childrentime commented 1 year ago

Never mind. I forked the devcert library and repackaged its ESM and CJS outputs using tsup. Now we can enable local HTTPS through the https option🎉🎉🎉.

childrentime commented 1 year ago

@Daydreamer-riri cc

Daydreamer-riri commented 1 year ago

Great! 🎉🎉🎉

One thing, I think we can use viteconfig.server.https directly as the configuration item, And state this in the documentation.

What do you think?

childrentime commented 1 year ago

You're right, I'll make the changes tomorrow

childrentime commented 1 year ago

@Daydreamer-riri cc

Daydreamer-riri commented 1 year ago

Great! Thank you for your contribution.

Daydreamer-riri commented 1 year ago

Hi @childrentime , I encountered a question:

image

Is there anything I missed?

system: Ubuntu 22.04.1 LTS WSL2

childrentime commented 1 year ago

@Daydreamer-riri I haven't tested its usability on the Linux platform, only tested macos. I just found that there are conditional statements in Linux that use dynamic require. I will submit another PR to modify it.

childrentime commented 1 year ago

Or you can upgrade the package @childrentime/devcert to version 1.2.8. I've just addressed this issue in this version.

childrentime commented 1 year ago

@Daydreamer-riri 哥,携程还招人不,捞我一个😭

Daydreamer-riri commented 1 year ago

@Daydreamer-riri 哥,携程还招人不,捞我一个😭

你给我发个邮件?我们邮件联系,我问一下我这边的