简体   繁体   English

NPM Run Build 始终构建生产而不是开发

[英]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.

相关问题 npm 运行构建生产不分发生产 - npm run build production does not distribute the production `react-hover` npm软件包不在生产版本中,但在开发中运行良好 - `react-hover` npm package not in production build but working fine in development 开发和生产期间的NPM版本 - NPM versions during development and production NPM生产开发上直播服务器 - NPM production and development on live server 打包后节点应用程序(生产和开发模式)的意外行为(npm run dist) - Unexpected behaviour of node app (both production and development mode) after packaging (npm run dist) npm 本地开发与生产 package 版本 - npm local development vs production package versions Node/WebpackDevServer/react-scripts,删除“To create a production build, use npm run build”消息 - Node/WebpackDevServer/react-scripts, remove “To create a production build, use npm run build” message on start 如何从发布管道 Azure DevOps 运行“npm run start”以在 NUXTJS 中启动生产构建? - How to run "npm run start" from release pipeline Azure DevOps to start production build in NUXTJS? 在OpenShift上运行npm install --production - Run npm install --production on OpenShift 在Heroku上的生产版本中显示开发版本错误 - Development build errors showing in production build on Heroku
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM