ant-design-vue
ant-design-vue copied to clipboard
Nitropack should not override NODE_ENV when run command nuxt generate.
- [x] I have searched the issues of this repository and believe that this is not a duplicate.
What problem does this feature solve?
I am developing an SSG project using Nuxt and Ant Design Vue. When I run the nuxt generate command, initially, the NODE_ENV is indeed set to production, which is as expected. However, during the pre-rendering phase, the NODE_ENV is overridden to prerender.
This results in Ant Design Vue generating incorrect class name prefixes. The relevant code is as follows:
File Path: ant-design-vue/es/_util/cssinjs/hooks/useCacheToken.js
const hashPrefix = process.env.NODE_ENV !== 'production' ? 'css-dev-only-do-not-override' : 'css';
The code that overrides NODE_ENV in Nitropack is as follows:
nitro.logger.info("Initializing prerenderer");
nitro._prerenderedRoutes = [];
nitro._prerenderMeta = nitro._prerenderMeta || {};
const prerendererConfig = {
...nitro.options._config,
static: false,
rootDir: nitro.options.rootDir,
logLevel: 0,
preset: "nitro-prerender"
};
And
let NODE_ENV = nitro.options.dev ? "development" : "production";
if (nitro.options.preset === "nitro-prerender") {
NODE_ENV = "prerender";
}
const buildEnvVars = {
NODE_ENV,
prerender: nitro.options.preset === "nitro-prerender",
server: true,
client: false,
dev: String(nitro.options.dev),
DEBUG: nitro.options.dev
};
What does the proposed API look like?
I know the main problem is in the nitropack not ant-design-vue. But maybe we could change the code like this.
const hashPrefix = process.env.NODE_ENV === 'development' ? 'css-dev-only-do-not-override' : 'css';
and at the same time, I also make a dicussion at here. https://github.com/unjs/nitro/discussions/2002
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days