[英]NPM Run Build Always Builds Production and Never Development
On an inherited project I have, I am trying to get the build command to build a version other than Production
.在我拥有的继承项目中,我试图获取 build 命令来构建
Production
以外的版本。
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.我试图更改
package.json
script
部分中的别名以传递额外的变量,例如--dev
和--configuration=dev
无济于事。
The project has these json data files:该项目有这些json数据文件:
env.dev
env.development
env.production
with the package.json
has this build alias build:dev
which I run npm run build:dev
:与
package.json
有这个构建别名build:dev
我运行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.这有效并构建,但仅适用于我在查看结果文件时验证的生产。
If I remove the file env.production
from the directory and run the build command, it fails with:如果我从目录中删除文件
env.production
并运行 build 命令,它会失败:
Creating an optimized production build...
Failed to compile.
Module not found: Error: Can't resolve 'polyfills' in 'C:\Work\MyProj\WebSiteName\src'
which just informs me that it can alias polyfills
found in the env.production
file for the location NODE_PATH=src/
.这只是告诉我,它可以别名
polyfills
在发现env.production
的位置文件NODE_PATH=src/
。
Thoughts?想法?
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"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.