Quasar: build with development mode - vue.js

I have in quasar.conf.js env settings with something like this:
env: {
API_URL: ctx.dev
? 'https://dev.apis.test.io/v2/'
: 'https://apis.test.io/v2/'
}
When I run app on local host dev api is used, when I run quasar build production api is used. So that is working.
How can I build with dev env settings?
For example on plain Vue yarn build --mode development works just fine. How can I do the same thing with quasar?
I tried:
quasar build --mode development
quasar build --mode dev
quasar build --development
quasar build --dev
quasar build --debug
and I always get production link in dist folder files

the answer above is not really wrong. You can do something like this:
create multiple .env files, for me best option is:
.env.local
.env.development
.env.production
inside quasar.conf.js use dotenv library:
const env = require('dotenv').config({ path: `.env.${process.env.ENV_FILE.toLowerCase()}` }).parsed
then put vars to quasar env:
build: {
vueRouterMode: 'history', // available values: 'hash', 'history'
env: {
...env
},
then run build for production or stage or run dev server with command:
ENV_FILE=development quasar build
For me it works like a charm, because i have more than two envs

try run
MY_API=api.com quasar build

Related

How can I enable HMR with Vue CLI and Yarn Workspaces?

I have a project with two packages:
components/
apps/
Both are built using #vue/cli, and I'm using yarn workspaces to manage dependencies.
Everything is working, except Hot Module Replacement when running the app.
components/package.json: main: dist/components.umd.js
app/package.json: components are a dependency, I import like import MyComponent from 'components'
In dev mode I run two tasks in parallel:
components: vue-cli-service build --target lib --watch
app: vue-cli-service serve
I want to change MyComponent in components/src/ and have it hot reload in the dev server.
However, I can only see the changes when I refresh the page.
I know the Vue cli splits source and vendor js bundles, so I thought this may be the cause of the problem?
Does anyone have any suggestions?

VuePress/Vue: Plugins not used during build using a GitLab CI

I'm looking to deploy a VuePress site using a Gitlab CI pipeline. I use some plugins via the method Vue.use().
When I build manually on my machine and deploy to firebase it works fine.
When the pipeline is triggered, it passes without issue, however, in the built files there is no trace of the plugins. In the case of Buefy, no Buefy component is generated in the built files.
Here's my EnhanceApp.js file:
import Buefy from 'buefy'
import 'buefy/dist/buefy.css'
export default ({
Vue,
options,
router,
siteData
}) => {
Vue.use(Buefy)
}
And here's my .gitlab-cy.yaml
image: node:10
deploy_production:
stage: deploy
environment: Production
only:
- master
script:
- npm install -g firebase-tools
- npm i
- npm run build
- firebase deploy -m "Pipeline $CI_PIPELINE_ID, build $CI_BUILD_ID" --non-interactive --token $FIREBASE_TOKEN
I tried both Firebase and AppEngine to no avail, as well as multiple docker images.
I'm not familiar with GitLab or firebase, but I suggest that you can try to use Yarn instead of npm. Because currently npm will cause some problems in Vuepress (e.g. make plugin-google-analytics unavailable).

custom env file names for vuejs modes beside dev and prod?

I have a vue.js app, and it is using two files named dev.env.js and prod.env.js to read environment variables and configure the app.
the dev.env.js is currently configured with data that our frontend developers are using.
I need to make some adjustments on my own and need another env file.
I have created a file named ninja.env.js next to the other files in config/ which contains:
'use strict'
module.exports = {
NODE_ENV: '"development"',
SERVER_PATH: '"localhost:8560"',
SOCKET_PATH: '"localhost:8561/map"'
}
but there is no way to run this.
I have tried:
$ npm run ninja
>>> npm ERR! missing script: ninja
$ npm run dev --mode ninja
>>> Failed to compile with 1 errors 11:12:02 AM
This dependency was not found:
* ninja in multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ninja
To install it, you can run: npm install --save ninja
so, is there a way to add multiple environment files?
Yes, as mentioned in docs, basically you can add different modes like this:
.env.[MODE_NAME]
And they you can run it like:
vue-cli-service build --mode [MODE_NAME]

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

Which command do I use to generate the build of a Vue app?

What should I do after developing a Vue app with vue-cli?
In Angular there was some command that bundle all the scripts into one single script.
Is there something the same in Vue?
I think you've created your project like this:
vue init webpack myproject
Well, now you can run
npm run build
Copy index.html and /dist/ folder into your website root directory. Done.
If you've created your project using:
vue init webpack myproject
You'd need to set your NODE_ENV to production and run, because the project has web pack configured for both development and production:
NODE_ENV=production npm run build
Copy dist/ directory into your website root directory.
If you're deploying with Docker, you'd need an express server, serving the dist/ directory.
Dockerfile
FROM node:carbon
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
ADD . /usr/src/app
RUN npm install
ENV NODE_ENV=production
RUN npm run build
# Remove unused directories
RUN rm -rf ./src
RUN rm -rf ./build
# Port to expose
EXPOSE 8080
CMD [ "npm", "start" ]
in your terminal
npm run build
and you host the dist folder. for more see this video
To deploy your application to prod environment add
"build": "vue-cli-service build --mode prod"
in your scripts in package.json file.
Open your main.js and add
Vue.config.productionTip = false;
right after your imports.
Then open your cli in the project folder and run this command
npm run build
This will make a dist folder in your project directory you may upload that dist folder in your host and your website will be live
If you run into problems with your path, maybe you need to change the assetPublicPath in your config/index.js file to your sub-directory:
http://vuejs-templates.github.io/webpack/backend.html
The vue documentation provides a lot of information on this on how you can deploy to different host providers.
npm run build
You can find this from the package json file. scripts section. It provides scripts for testing and development and building for production.
You can use services such as netlify which will bundle your project by linking up your github repo of the project from their site. It also provides information on how to deploy on other sites such as heroku.
You can find more details on this here
The commands for what specific codes to run are listed inside your package.json file under scripts. Here is an example of mine:
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
If you are looking to run your site locally, you can test it with
npm serve
If you are looking to prep your site for production, you would use
npm build
This command will generate a dist folder that has a compressed version of your site.
THIS IS FOR DEPLOYING TO A CUSTOM FOLDER (if you wanted your app not in root, e.g.
URL/myApp/) - I looked for a longtime to find this answer...hope it helps someone.
Get the VUE CLI at https://cli.vuejs.org/guide/ and use the UI build to make it easy. Then in configuration you can change the public path to /whatever/ and link to it URL/whatever.
Check out this video which explains how to create a vue app using CLI if u need more help: https://www.youtube.com/watch?v=Wy9q22isx3U
For NPM => npm run Build
For Yarn => yarn run build
You also can check scripts in package.json file
You write down the below command being at the project root.
npm run build
First Install Vue Cli Globally
npm install -g #vue/cli
To create a new project, run:
vue create project-name
run vue
npm run serve
Vue CLI >= 3 uses the same vue binary, so it overwrites Vue CLI 2 (vue-cli). If you still need the legacy vue init functionality, you can install a global bridge:
Vue Init Globally
npm install -g #vue/cli-init
vue init now works exactly the same as vue-cli#2.x
Vue Create App
vue init webpack my-project
Run developer server
npm run dev
This command is for start the development server :
npm run dev
Where this command is for the production build :
npm run build
Make sure to look and go inside the generated folder called 'dist'.
Then start push all those files to your server.
One way to do this without using VUE-CLI is to bundle the all script files into one fat js file and then reference that big fat javascript file into main template file.
I prefer to use webpack as a bundler and create a webpack.conig.js in the root directory of project. All the configs such as entry point, output file, loaders, etc.. are all stored in that config file. After that, I add a script in package.json file that uses webpack.config.js file for webpack configs and start watching files and create a Js bundled file into mentioned location in webpack.config.js file.
I think you can use vue-cli
If you are using Vue CLI along with a backend framework that handles static assets as part of its deployment, all you need to do is making sure Vue CLI generates the built files in the correct location, and then follow the deployment instruction of your backend framework.
If you are developing your frontend app separately from your backend - i.e. your backend exposes an API for your frontend to talk to, then your frontend is essentially a purely static app. You can deploy the built content in the dist directory to any static file server, but make sure to set the correct baseUrl
npm run build - this will uglify and minify the codes
save index.html and dist folder in root directory of your website.
free hosting service that you might be interested in -- Firebase hosting.
if you used vue-cli and webpack when you created your project.
you can use just
npm run build command in command line, and it will create dist folder in your project. Just upload content of this folder to your ftp and done.
If you are using npm u can use npm run build but if you are using yarn you can simply run yarn build
If you want to create a build for a domain, you can use the $ npm run build command.
If you're going to build for a sub-domain, follow these instructions:
Create a file that's name is vue.config.js in the root
Write down the below code in the vue.config.js file:
module.export = {
publicPath: '/demo-project',
}
Now run $ npm run build
Note: Use your subdomain name instead of "/demo-project".
If you want to build and send to your remote server you can use cli-service (https://cli.vuejs.org/guide/cli-service.html) you can create tasks to serve, build and one to deploy with some specific plugins as vue-cli-plugin-s3-deploy