Difference of using (--prod and prod) command - angular8

While production of my file am using
npm run build -- --c prod
npm run build -- --c --prod
above both that --prod and prod difference i need , while run both has been running but --prod fast and prod system hang and taking time and can any one clarify me about using (--)in command prompt

The --prod option will make Angular to make the application much smaller in size.
This is the reason why --prod is faster.
From documentation:
--prod=true|false
Shorthand for "--configuration=production". When true, sets the build configuration to the production target. By default, the production target is set up in the workspace configuration such that all builds make use of bundling, limited tree-shaking, and also limited dead code elimination.
For < Angular 5:
ng build --prod --build-optimizer

Related

How to chain vite build and tests?

It seems that vite build command doesn't run tests (unit tests written with vitest, for example) before building the application for production. This is quite unsafe.
Is there a way to configure vite build to run tests before trying to build ?
I couldn't find anything in Build Options.
What do you have in your package.json, scripts section? Don't you have some test or alike?
build is used to bundle your app and ship it to production. It's not supposed to run any tests by default.
You could achieve this by doing something like
"scripts": {
"build": "vite build && npm run test:unit && npm run test:e2e",
"test:unit": "vitest --environment jsdom",
"test:e2e": "start-server-and-test preview http://localhost:4173/ 'cypress open --e2e'",
},
If you generate a new project via the CLI, you will have most of them already written for you, then it's a matter of properly chaining them with && to assure that they are all succeeding before proceeding further.
You can also add some Git hooks with something like husky + lintstaged so that your flow is using something by default before even pushing it to a remote repo.
Otherwise, it's part of your CI. Either it be a Docker compose file, some Github actions, Gitlab pipelines or anything your devops team could have setup for your deploy environments.

NODE_ENV=production with react-app-rewired

I have installed react-app-rewired as dev dependency according to docs.
"devDependencies": {
//...
"react-app-rewired": "^2.1.8",
},
Now I'd like to make a production build. When I use
NODE_ENV=production yarn install
consequent yarn build says that react-app-rewired: not found (because it is in dev only).
Does yarn build implies production under the hood?
If so, why do I need all the dev dependencies to be installed to make a production build?
Should I get rid of NODE_ENV or move react-app-rewired to production then?
When making the production build (when you need to transform your code, generate built assets, etc.), you usually need to have the dev dependencies installed since the dev dependencies contain the build tools needed to transform/compile the code into production code. When running the actual production code that is built from running yarn build, then you'd only need to have the production dependencies installed.
So, before the app is actually built, you need to run yarn install without NODE_ENV=production. Once the app is built (i.e. once you've ran yarn build and you have all the code transformed, all artifacts generated, etc.), then you'd re-run yarn install but with production mode turned on (NODE_ENV=production yarn install) so yarn only installs the dependencies in the dependencies section of package.json (these are the dependencies that your transformed code would depend on, whereas the build tools like react-app-rewired are only needed at build-time).

In create-react-app, does the development build 'npm start' get output to the filesystem?

I have a create-react-app. It works great, however, where does the output to npm start get served from, i.e, what is the path on disk? Or does it get served from memory?
I would like to serve that output from IIS to avoid some cross-origins issues with a webservice I am calling but I can't find the physical disk path where npm start is being output.
I would run npm run build every time but it takes a solid 2 minutes and I want the faster build time of the non-optimized build for debugging.
create-react-app uses react-scripts to compile the code. Have you considered setting up dev environments?
First:
$ npm install dotenv-cli --save-dev
package.json
{
...
"scripts": {
...,
"build": "react-scripts build",
"build-dev": "dotenv -e .env.development
react-scripts build",
...
}
...
}
Alternatively, you can run this command and use webpack or something else to bundle
npm run eject
Note: this is a one-way operation. Once you eject, you can’t go back!
If you aren’t satisfied with the build tool and configuration choices, you can eject at any time. This command will remove the single build dependency from your project.
Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc.) into your project as dependencies in package.json. Technically, the distinction between dependencies and development dependencies is pretty arbitrary for front-end apps that produce static bundles.
In addition, it used to cause problems with some hosting platforms that didn't install development dependencies (and thus weren't able to build the project on the server or test it right before deployment). You are free to rearrange your dependencies in package.json as you see fit.
All of the commands except eject will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
You don’t have to ever use eject. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.

How do I optimize build of custom mode in vue cli 3

We can set custom modes in cli 3.
Because it is not a production mode, it would not be a optimized build.
How do I set config to custom mode to reach the optimized build as production mode.
custom mode(staging) in package.json
The files of default production mode(optimized), command: npm run build
The files of custom mode(staging) (not optimized), command: npm run staging
Thanks in advance.
I think you are Mixing between two things first vue build app.vue command builds a production ready bundle.
Modes are just another name for environment, which specifies if you’re in development, production or test mode.
if you want to associate different mode with your build you can append it like that vue-cli-service build --mode development. by --mode you assign what environment variables you need with that build.
if you want the stage build to be optimized as production just put NODE_ENV=production in the start of your .env.staging file .
ref: CLI docs modes and env in cli docs

npm run build --mode [.env.mode] not working as expected

What I've done so far:
I've been trying to setup multiple build modes like staging, testing, production and development based on NODE_ENV=production. So I'm keeping the respective files in the root of the project folder like:
.env.production
.env.staging
.env.testing
.env.development
Now, all these files are having
NODE_ENV=production
VUE_APP_ENV=<mode>
The document that I followed clearly states that,
vue-cli-service build --mode staging builds a production app in
staging mode, using .env, .env.staging and .env.staging.local if they
are present.
Problem:
As expected, running the command npm run build --mode staging is to give a production build with variable as listed in the .env.staging file. However, production variables are loaded instead of staging.
Ref:
https://cli.vuejs.org/guide/mode-and-env.html#example-staging-mode
https://forum.vuejs.org/t/how-to-build-production-app-with-varying-config/29708
You need to use the following command
npm run build -- --mode staging
All arguments before -- are considered npm arguments and arguments after -- are passed to vue-cli-service
I was having the same problem, I figured out my problem was from using a beta version (3.0.0-beta.9) of #vue/cli-service so changing it to the rc version (3.0.0-rc.3) worked. So in my package.json under devDependencies I changed it to "#vue/cli-service": "^3.0.0-rc.3"