Run webpack in a Google Cloud Builder step - npm

I am trying to pack a web app using Google Cloud Builder.
I already have npm install working in a previous step of the same build.
File webpack.config.js is ready to use and tested outside Google Cloud Builder. It is cloned inside the /workspace in a previous step of this build.
How do I execute webpack command as a build step?

This is how I manage to run webpack inside Google Cloud Builder configuration script.
I had to use the npx in order to execute it using the npm docker image.
This is a step to run webpack and goes inside the file cloudbuild.yaml
# run webpack
- name: 'gcr.io/cloud-builders/npm'
entrypoint: 'npx'
args: ['webpack']
dir: '${_MY_APP_DIR}templates/react_app/build'
timeout: 10s

Assuming you are using webpack version >=4:
webpack --mode=production --config ./webpack.config.js

Related

Nuxt: Command 'nuxt' not found - Output directory `dist/` does not exists

I have successfully created a Nuxt.js project with this configuration using the CLI:
Project name: test
Programming language: JavaScript
Package manager: Npm
UI framework: None
Nuxt.js modules: None
Linting tools: None
Testing framework: None
Rendering mode: Single Page App
Deployment target: Static (Static/JAMStack hosting)
Development tools: jsconfig.json
Version control system: Git
The developement server runs properly with npm run dev.
npm run build also runs without errors and tells me that:
Ready to run nuxt generate
But the execution of nuxt generate leads to the error Command 'nuxt' not found. This is strange because nuxt seems to be installed when I execute npm nuxt list.
I first reinstalled just nuxt and then all dependencies after deleting the node_modules/ folder, but the error remains the same. If I just run npm run start it tells me
Nuxt Fatal Error
Error: Output directory `dist/` does not exists, please use
`nuxt generate` before `nuxt start` for static target.
This is strange again because the .nuxt/dist/ folder exists.
Does anyone have an idea what is going wrong?
I have solved the problem. For me it works if I run npm run generate instead of nuxt generate.

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 (or latest) npm version in Google Cloud Builder

I'm using Google Cloud Builder (GCB) to build some Node.js code. I'm using npm's new package-lock.json feature to pin dependencies. This works best when using the npm ci command that was introduced in npm#5.7.1. Unfortunately, all of GCB's npm images are currently set to npm#5.6.0
How can I use a different npm version in GCB without creating a custom builder image?
Edit: It may not be the case that all of GCB's images are set to npm#5.6.0, but the one that I need to use (node-8.11.0) is set to this version.
I solved the issue by creating my own container image based on the cloud-builder's npm image.
Dockerfile:
FROM gcr.io/cloud-builders/npm:node-8.11.0
ARG NPM_VERSION
RUN npm i -g npm#${NPM_VERSION}
ENTRYPOINT ["npm"]
cloudbuild.yaml:
steps:
- name: 'gcr.io/cloud-builders/docker'
args:
- 'build'
- '--build-arg=NPM_VERSION=latest'
- '--tag=gcr.io/$PROJECT_ID/npm:latest'
- '.'
images:
- 'gcr.io/$PROJECT_ID/npm:latest'
I ran gcloud builds submit . --config=cloudbuild.yaml from the same folder containing the Dockerfile and cloudbuild.yaml files. This submitted the build to GCB and posted an image in my project's container registry. I then used this image in my other project's cloudbuild.yaml that needed the upgraded npm version, like so:
steps:
- id: frontend_install
name: 'gcr.io/$PROJECT_ID/npm:latest'
args: ['ci']
waitFor: ['-']
After doing this, everything works as expected.

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

How to run build in local machine with drone.io

Does the build have to run on the drone.io server? Can I run the build locally? Since developers need to pass the build first before pushing code to github, I am looking for a way to run the build on developer local machine. Below is my .drone.yml file:
pipeline:
build:
image: node:latest
commands:
- npm install
- npm test
- npm run eslint
integration:
image: mongo-test
commands:
- mvn test
It includes two docker containers. How to run the build against this file in drone? I looked at the drone cli but it doesn't work in my expected way.
#BradRydzewski comment is the right answer.
To run builds locally you use drone exec. You can check the docs.
Extending on his answer, you must execute the command in the root of your local repo, exactly where your .drone.yml file is. If your build relies on secrets, you need to feed these secrets through the command line using the --secret or --secrets-file option.
When running a local build, there is no cloning step. Drone will use your local git workspace and mount it in the step containers. So, if you checkout some other commit/branch/whatever during the execution of the local build, you will mess things up because Drone will see those changes. So don't update you local repo while the build is running.