nextjs - 下一个使用 NODE_ENV=development 构建 [英] nextjs - next build with NODE_ENV=development

查看:43
本文介绍了nextjs - 下一个使用 NODE_ENV=development 构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将我的 nextjs 项目构建为 development 模式.

I'd like to build my nextjs project as development mode.

我试过了

package.json

{
  ...
  "scripts": {
    "dev": "next",
    "build:dev": "set NODE_ENV=development & next build",
    "build:prod": "set NODE_ENV=production & next build",
    "start:dev": "set NODE_ENV=development & next start",
    "start:prod": "set NODE_ENV=production & next start"
  }
  ...
}

next.config.js

module.exports = withSass({
  env: {
    baseUrl: process.env.NODE_ENV === "development" ? "devServerURL": "prodServerURL"
  }
});

但我无法实现我想要的.

but I couldn't achieve what I want.

所以,我尝试了一些改变.

so, I tried with some change.

package.json

  "scripts": {
    "dev": "next",
    "build": "next build",
    "start:dev": "set NODE_ENV=development & next start",
    "start:prod": "set NODE_ENV=production & next start"
  }

但它也不起作用.

如何在开发模式下构建next?

How can I build the next with development mode?

提前致谢.

编辑

我的操作系统是 Windows 10.

My OS is Windows 10.

推荐答案

参见问题 #9123,(2019 年 10 月 18 日):

NODE_ENV 是一个不能更改的保留环境变量.唯一有效的值是生产、开发和测试.

NODE_ENV is a reserved environment variable that cannot be changed. The only valid values are production, development, and test.

如果您需要在不同的生产环境中更改应用行为环境,请使用不同的变量,例如 APP_ENV.

If you need your app behavior to change in different production environments, please use a different variable like APP_ENV.

以及 问题 #17032(2020 年 9 月 12 日):

process.env.NODE_ENV 只有 2 个可能的值 development生产.如果未将其设置为该值,您将遇到各种情况您获得的库边缘案例(尤其是在 node_modules 中)严重去优化的结果.例如.如果您进行性能测试如果 process.env.NODE_ENV 不是,你会得到明显更差的结果投入生产

process.env.NODE_ENV only has 2 possible values development and production. If this is not set to that value you'll run into all kinds of library edge cases (especially in node_modules) where you get severely de-optimized results. E.g. if you run a performance test you'll get significantly worse results if process.env.NODE_ENV is not set to production

这篇关于nextjs - 下一个使用 NODE_ENV=development 构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆