ant-design-vue icon indicating copy to clipboard operation
ant-design-vue copied to clipboard

Nitropack should not override NODE_ENV when run command nuxt generate.

Open kaokei opened this issue 1 year ago • 1 comments

  • [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

kaokei avatar Dec 13 '23 08:12 kaokei

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

github-actions[bot] avatar Feb 12 '24 02:02 github-actions[bot]