-
Notifications
You must be signed in to change notification settings - Fork 0
VueJS Service
-
Installing
NPMpackages. Usually withyarn -
Populate the
.envfile. More details here -
Now you can serve the app
-
Start serving the app with
yarn serve-
Note:
serve-ing the frontend is not designed for production, i.e. it shares source maps and non minified code. In big lines, this command does: (what we know / reverse engineered) -
This command starts the VueJS Frontend (with its respective nodeJS backend) with the help of the
vue-cli-servicewhich does a few more things because web is web and you need to compileTScode intoJS.-
Compilation steps (that we know of / reverse engineered)
- Vue cli stores somewhere the compiled
JSand source maps. - It uses babel to polyfill
JScode for older browsers. What polyfill is: Polyfill
- Vue cli stores somewhere the compiled
-
After compilation, it starts preloading some settings, some of them are:
- Sets environment variables. The precedence is:
- Command line argument environment variable
- Environment variable specified in
.envfile - Previously set environment variables (similar to if you type
ENV_VAR=somethingbefore you run anything) - Maybe some shady defaults the Vue framework has? But not for everything of course
- Finally, the
TypeScriptcode you wrote is being executed. Good luck!
-
-
Environment variables are values that your shell remembers for you, or if you are in a program, can query the operating system to tell you for example "hey what operating system is this?" (e.g. the OS variable on most POSIX systems).
Because running the app in production is different than just developing or testing, we also want to control our code without rewriting code or having to recompile it just to hide some prints. This is where environment variables come in. You can know programmatically if you are in "production" or "development", and also many other "settings"
In the frontend and backend folders of our project, we use a standard way to store environment variables, which is in a file named .env in the top-level directory. (Sibling to package.json for example)
- When we talk about environments, we mainly talk about
developmentandproductionenvironments. Although a sometimestestis also used.
- For rapid switching between environments or if you just want to write them once and then be able to set them easily, just write the files
.env.prodand.env.devand place them in the sameenvfolder with the samples. After you are done writing the secrets and the rest of the variables, you can use commandsyarn set-env-prodandyarn set-env-devthat simply copy your.env.<environ>file to overwrite the.envfile at the root of the frontend project