NPM Run Build Always Builds Production and Never Development

笑着哭i 提交于 2019-12-10 21:57:37

问题


On an inherited project I have, I am trying to get the build command to build a version other than 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.


The project has these json data files:

 env.dev
 env.development
 env.production

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.


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'

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

Thoughts?


回答1:


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"



来源:https://stackoverflow.com/questions/55092940/npm-run-build-always-builds-production-and-never-development

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!