-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changing the output path parameter 'base' failed to build successfully? #80
Comments
Did you try to prepend /demo/ to the routes to render? |
I'm not quite sure how to add it before the route to be rendered? |
Just |
This is not enough to work, because:
I managed to find a workaround at least for my case, Let's assume that base path is // We're behind the proxy. Thus, we need to define these for prerenderer:
// Strip base prefix from the urls. Prerenderer will take our base as /
const urlModifier = (s: string) => s.replace(env.BASE_URL.substr(1), '');
// Ensure prerenderer's server will serve our public assets correctly (they are not in rollup bundle|
const hookServer = (app: express.Application) => {
app.use(env.BASE_URL || '/', express.static('./dist'));
};
// Make prerenderer output our files correctly, route by route. In my simple case we have only one route, so just output is where needed.
const postProcess = (r: RenderedRoute) => { r.outputPath = 'index.html'; } (all three is needed. urlModifier is for assets in bundle, hookServer is for assets not in bundle, postProcess for output) prerenderer({ routes: [env.BASE_URL || '/'], rendererOptions: { renderAfterTime: 1000 },
server: { before: hookServer },
postProcess: postProcess,
urlModifier: urlModifier
}); сс @Tofandel this is a closed issue so I ping you, (1) maybe it's useful to add basePath to prerenderer options, (2) idk how to do it without a deprecated |
The To not use the deprecated option you simply need to do this prerenderer({ routes: [env.BASE_URL || '/'], rendererOptions: { renderAfterTime: 1000 },
postProcess: postProcess,
urlModifier: urlModifier
}).hookServer(hookServer); I have access to the base url of vite (rollup doesn't have one) or webpack config so I should be able to alter the output path and make routes be relative to the base path (will be a breaking change but I can add an option Could you share your full vite/rollup config so I can have a better understanding |
Thanks for the response! ❤️
Ah, interesting. I use https://github.com/i18next/react-i18next, and it just uses json locales as they're needed, that's why assets aren't registered.
As for vite.config.ts, here it is import react from '@vitejs/plugin-react';
import { defineConfig, loadEnv } from 'vite';
import svgr from 'vite-plugin-svgr';
import prerenderer from '@prerenderer/rollup-plugin';
import type { RenderedRoute } from '@prerenderer/prerenderer';
import express from 'express';
export default defineConfig(({ command, mode }) => {
const env = loadEnv(mode, process.cwd(), '')
// We're behind the proxy. Thus, we need to define these for prerenderer:
// Strip base prefix from the urls. Prerenderer will take our base as /
const urlModifier = (s: string) => s.replace(env.BASE_URL.substr(1), '');
// Ensure prerenderer's server will serva our public assets correctly (they are not in rollup bundle|
const hookServer = (app: express.Application) => {
app.use(env.BASE_URL || '/', express.static('./dist'));
};
// Make prerenderer output our files correctly, route by route.
const postProcess = (r: RenderedRoute) => { r.outputPath = 'index.html'; };
return {
plugins: [react(), svgr(),
prerenderer({ routes: [env.BASE_URL || '/'], rendererOptions: { renderAfterTime: 1000 },
server: { before: hookServer },
postProcess: postProcess,
urlModifier: urlModifier
})
],
resolve: {
alias: [{ find: '@', replacement: '/src' }],
},
base: env.BASE_URL || "/",
esbuild: {
supported: {
'top-level-await': true
},
},
}
}); |
Yes I see that https://github.com/i18next/react-i18next is using http to load locales instead of using the import.meta.glob build system so that's why it's outside the scope
Okay I see that vite has a One thing to look out for is that we are building the page before it's output to the filesystem by rollup, that's why you won't see any express.static in this lib because the files don't exists at the time we prerender, we serve them entirely from memory, it's okay if you point it to the sources but pointing it to dist could cause problems, maybe they don't exist on the first build and then they will be one version behind (Vite seems to copy the files at the same time it cleans the outDir and so way before the build emits that's why your setup works) I would still recommend changing to this
My bad, that's only on the prerender instance not the plugins, I'll aim to fix this as well |
This is essential. Didn't know anything about So, should we sum up and outline the new issues?
Am I correct? Should we post them as new issues? |
Hi,
When I change the output path parameter base, an error occurs during the build process
The text was updated successfully, but these errors were encountered: