Unable to deploy VueJS with Gitlab Pages - vue.js

I have used Gitlab pages in the past for React deployment and they work well except for VueJS. After following the example here, I'm still unable to generate a website link for my Gitlab page even after GitLab CI pipeline was successful. Can anyone help with this?
This is what the .gitlab-ci.yml looks like:
# .gitlab-ci.yml file to be placed in the root of your repository
pages: # the job must be named pages
image: node:latest
stage: deploy
script:
- npm ci
- npm run build
- mv public public-vue # GitLab Pages hooks on the public folder
- mv dist public # rename the dist folder (result of npm run build)
artifacts:
paths:
- public # artifact path must be /public for GitLab Pages to pick it up
only:
- master
This is what the vue.config.js looks like:
// vue.config.js file to be place in the root of your repository
// make sure you update `yourProjectName` with the name of your GitLab project
module.exports = {
publicPath: process.env.NODE_ENV === 'production'
? '/yourProjectName/'
: '/'
}
After committing and pushing my changes, the GitLab CI pipeline was changed from running to successful. I was expecting to see my website link on Settings > Pages. I clicked on it, but I didn't see it. What could be wrong?

Maybe is a problem of you assets links:
Because normaly in you local host you have all js files in a public folder, where you react or vuejs project join with you .html page with only a /assets/vuejs.files.js, so for deploy you need to rebase you url
This is a documentation for vite project deploy
https://vitejs.dev/guide/static-deploy.html
where explain that you neet to rebase you url, example:
for you localhost:8000/ all files are in localhost:8000/assets/transpiled.vue.js but for deploy you url gona be diferent than https://gitlab.com/<USERNAME>/<REPO> where you base URL is '/<REPO>/'.
Necessary to do it changes, if not you build project will request you assets file into / default base url, but not exist so, will redirect to gitlab and will redirect this again to login, so for this is you problem CORS.

Related

empty site after using nmp run build (vue 2 cli)

Im using project vue 2 cli + vuex + router (without history mode) but when Im opening index.html, after "nmp run build" command, site is empty. How can I solve it... I need site to be opened on index.html (like common cdn project)
The dist directory is meant to be served by an HTTP server (unless you've configured publicPath to be a relative value), so it will not work if you open dist/index.html directly over file:// protocol.
Source
One way to test your build, is to install Serve:
// install Serve globally
npm install -g serve
// Run in project root, with folder name as input
serve -s dist

Problem with deploy Nuxt.js in GitHub Pages

I recently started learning Nuxt.Js and faced with the problem of deployment on GitHub Pages.
I do everything according to the instructions:
https://medium.com/#kozyreva.hanna/nuxt-js-gh-pages-deployment-73b88aa3aa65
Infinite nuxt-loading appears on gh-pages instead of content.
GitHub: https://github.com/Owe7x/slide
GH-pages: https://owe7x.github.io/slide/
What could be the problem?
I've already tried to follow that steps and they didn't work for me, after some researches I ended up with following steps :
remove the dist entry from .gitignore file
run npm run generate
run git add . then git commit -m "deploy on gh-pages"
We need to add router base configuration in nuxt.config.js:
target: 'static',
router: {
base: '/<repository-name>/'
}
run git subtree push --prefix dist origin gh-pages
Make sure to delete the current gh-pages branch before running these commands.

build and publish dist folder to github pages

I created a project with Vue.js and Vuetify using the Vue CLI. I would like to host this application with Github Pages. So I took a guide from here
https://help.github.com/en/articles/configuring-a-publishing-source-for-github-pages#publishing-your-github-pages-site-from-a-docs-folder-on-your-master-branch
and I am not using the history moute of the Vue Router (https://router.vuejs.org/guide/essentials/history-mode.html) to make sure I don't need a server.
I created a build of my project and renamed the generated dist folder to docs. This docs folder is placed in the root directory (where it was generated). When I select master branch /docs folder as my Github Pages publishing source I get a blank white page.
When I check the console I get a
Failed to load resource: the server responded with a status of 404 ()
for each file generated in the dist/docs folder. What am I missing?
This could be that the root path of your app is set to look at the root of your github instead of the root of the repository.
It also looks like you are using vue-cli-3 from the tags. So here is what I have done for deploying a Vue app to be hosted on github pages.
Create a vue.config.js file in the root of your app.
In that file, set the public path to match the repository name.
module.exports = {
publicPath: process.env.NODE_ENV === 'production' ? '/YOUR_REPO_NAME/' : '/'
}
Create a deploy.sh file in the root of your app.
In the file, write the following
set -e
npm run build
cd dist
git init
git add -A
git commit -m 'deploy'
git push -f git#github.com:YOUR_USER_NAME/REPOSITORY_NAME.git master:gh-pages
cd -
Now from the command line, in the root of your app, you can run sh deploy.sh. This will run the build command for vue-cli, go into the dist folder, commit those files and push them to the gh-pages branch.
Then you can set your github repo to use gh-pages instead of docs. Since you mentioned you are not using history mode for vue-router, you should see the # in the URL string and it will work when a user refreshed the page on a different route other than home.
Hope that helps point you in the right direction for deploying and hosting your Vue app on github pages.
I add vue.config.js file, and modify webpack config,like this
module.exports = {
outputDir: 'docs'
}

Vuejs Gitlab page is blank, console says MIME type mismatch, css and js not found

I made a website in Vuejs, it works on my local browser. I build the page locally and push to gitlab here (https://gitlab.com/ayaderaghul/coi6), and run CI (with folder: public). The page is blank (https://ayaderaghul.gitlab.io/coi6/), the console says:
The resource from “https://ayaderaghul.gitlab.io/coi6/public/static/js/vendor.d5bde172b988351183eb.js” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff).[Learn More] coi6
Loading failed for the <script> with source “https://ayaderaghul.gitlab.io/coi6/public/static/js/vendor.d5bde172b988351183eb.js”.
And I right click the page to View Page Source, the link to css, js files are not found (view-source:https://ayaderaghul.gitlab.io/coi6/)
I have tried the following:
I write commands to build the page in .gitlab-ci.yml
image: alpine:latest
before_script:
- apk add --update nodejs
- apk add --update npm
- npm install chalk
- npm install each-async
- npm install indent-string
- npm install
pages:
stage: deploy
script:
- npm run build
artifacts:
paths:
- public
only:
- master
(https://gitlab.com/ayaderaghul/coi6/blob/master/.gitlab-ci.yml)
I change the css and js paths in file index.html in some ways: /coi6/public/static/css/... or static/css/... ...
None of them works. The behavior is the same. Please give me more options to try? Or more cues to look at? Or explain me something I haven't understood. Thank you,
Your path is wrong in index.html.
Your files are available for example here :
https://ayaderaghul.gitlab.io/coi6/static/js/vendor.d5bde172b988351183eb.js
Whereas you are referencing them here :
https://ayaderaghul.gitlab.io/coi6/public/static/js/vendor.d5bde172b988351183eb.js

Nuxt deployment error: server resources are not available

To deploy our nuxt website in ssr mode we first build and unit test website in the bitbucket pipeline and if tests are green we copy build files from bitbucket servers to our production server and trigger start.
The problem is that Nuxt documentation says nothing about which exact files are required on the server.
currently we are using:
.nuxt/
server/
static/
nuxt.config.js
Sometimes after adding functionality to the website, deployed version throws an error:
Error: Server resources are not available!
At the same time local version works fine.
Also running production server locally on the project works.
Error kinda hints that some paths picked up incorrectly by nuxt.. but the directory structure is completely the same.
Any ideas why this happens and how to fix that?
If errors also mentions, Please check "file path"/.nuxt/dist/server existence.
Then on the terminal
cd .nuxt
check if 'dist' folder exists. If it does not exists,
go back and npm run build. this will generate the 'dist' folder for use.
If Still facing the issue, try,
npm install --save nuxt
npm install --save vue-server-renderer
Try adding: dev: process.env.NODE_ENV === 'DEV' to nuxt.config.js