NPM运行构建始终构建生产而从未开发 [英] NPM Run Build Always Builds Production and Never Development

查看:376
本文介绍了NPM运行构建始终构建生产而从未开发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我拥有的继承项目上,我试图获取build命令来构建除Production以外的版本.

On an inherited project I have, I am trying to get the build command to build a version other than Production.

我试图更改package.jsonscript部分中的别名,以将多余的变量(例如--dev--configuration=dev)传递给无效.

I have attempted to change the alias in the script section in package.json to pass in extra variables such as --dev and --configuration=dev to no avail.

该项目具有以下json数据文件:

The project has these json data files:

 env.dev
 env.development
 env.production

具有package.json

具有此构建别名build:dev,我可以运行npm run build:dev:

with the package.json has this build alias build:dev which I run npm run build:dev:

"scripts": {
    "start": "NODE_ENV=dev && react-scripts start",
    …
    "build:dev": "npm run build --dev --configuration=dev && react-scripts build"
}

这有效并且可以构建,但是仅用于生产,当我查看结果文件时才进行验证.

This works and builds, but for production only which I verify when I view the resultant files.

如果我从目录中删除文件env.production并运行build命令,它将失败并显示以下信息:

If I remove the file env.production from the directory and run the build command, it fails with:

Creating an optimized production build...
Failed to compile.

Module not found: Error: Can't resolve 'polyfills' in 'C:\Work\MyProj\WebSiteName\src'

这只是告诉我,它可以对在env.production文件中找到的polyfills别名为位置NODE_PATH=src/.

which just informs me that it can alias polyfills found in the env.production file for the location NODE_PATH=src/.

有想法吗?

推荐答案

您需要设置环境.变量,就像您在调用构建命令之前在开始"中所做的一样.

you need to set the env. variable like you do in "start" before calling the build command.

"build:dev": "NODE_ENV=dev npm run build --dev --configuration=dev && react-scripts build"

这篇关于NPM运行构建始终构建生产而从未开发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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