DreaMinder / nuxt-payload-extractor

Nuxt.js module that makes `nuxt generate` command to store html and payload separately.
MIT License
145 stars 18 forks source link

Running generate() under a cloud function #23

Closed EyePulp closed 3 years ago

EyePulp commented 3 years ago

Hey @DreaMinder I was hoping I could ask you some questions about your work on this issue, which was closed: https://github.com/nuxt/nuxt.js/issues/3798

I'm trying to get generate() to work under a Google Cloud Function, and running into problems and would really appreciate talking to you about it.

Happy to pay for your time, and appreciate any help you can provide. Sorry to bug you via this project, I didn't know any better way to reach out.

Thanks!

DreaMinder commented 3 years ago

Hey @EyePulp It was just a PoC for one of my projects, which I never used. So I'm not sure I'll be able to help, but let's try. You can write me here, or on Telegram. I'll do my best, for free (but don't expect quick responses 🙏).

EyePulp commented 3 years ago

Howdy @DreaMinder; Thanks so much for the response. I do apologize for bothering you but it was very nice of you to write back.

I finally got past the issue that caused me to contact you, which was mainly adding dev:false to the nuxt.config.js.

I figured out I need to do the nuxt build locally, and then pass the contents of buildDir as part of the bundle when I deploy to GCF if I wanted things to be fast enough. GCF just runs a programmatic generate step. Here's what it looks like right now:

const { Nuxt, Builder, Generator } = require('nuxt-edge');
const ConfigServer = require('./configServer');

async function generate({ nuxtConfigPath, storagePath, distDir, config }) {
    const nuxtConfig = require(nuxtConfigPath);
    nuxtConfig.dev = false;
    nuxtConfig.sitemap = { hostname: 'https://example.com' };
    nuxtConfig.generate.dir = distDir;
    const nuxt = new Nuxt(nuxtConfig);

    const configServer = await ConfigServer(config);
    const builder = await new Builder(nuxt);
    const results = await new Generator(nuxt, builder).generate({ build: false, init: true });
    configServer.close();
    return results;
}
module.exports = generate;

I'm running into other problems, but I think I can sort them out without bothering you any further.

Thanks again for your time and attention!

DreaMinder commented 3 years ago

I'm happy to see you figred it out, great job! Yeah, .dev should be false, not sure why I didn't use it in my code, maybe because I had NODE_ENV==='production' env var.

Overall, the biggest issue I faced - is uploading dist dir to somewhere else. Ideally, the target CDN should support .zip files, otherwise uploading 1000 files at once could be slow and unreliable.