Skip to content

Instantly share code, notes, and snippets.

@josephrace
Created May 18, 2017 17:44
Show Gist options
  • Select an option

  • Save josephrace/719bfc7e40f632fd7aa3940ef1ede59e to your computer and use it in GitHub Desktop.

Select an option

Save josephrace/719bfc7e40f632fd7aa3940ef1ede59e to your computer and use it in GitHub Desktop.
Configuration file for create-react-app on GitLab Pages
image: node:7.9.0 # change to match your node version
cache:
paths:
- node_modules/
before_script:
- npm install
test:
stage: test
script:
- CI=true npm test
pages:
stage: deploy
script:
- CI=true npm run build
- rm -rf public
- mv build public
artifacts:
paths:
- public # GitLab pages serve from a 'public' directory
only:
- master # run on master branch
@josephrace

josephrace commented May 18, 2017

Copy link
Copy Markdown
Author

Note, you will need to specify a homepage value in package.json unless you are using a custom domain where the app is served from the root.

https://create-react-app.dev/docs/deployment/#building-for-relative-paths

@will-moore

Copy link
Copy Markdown

Thanks, I used your example and it seemed to run OK, see https://gitlab.com/openmicroscopy/incubator/omero-idr-gallery/-/jobs/87247109
However, I can't see the page deployed anywhere. I expected it to be at https://openmicroscopy.gitlab.io/incubator/omero-idr-gallery/
but this is 404.
Any pointers would be much appreciated, thanks.

@will-moore

Copy link
Copy Markdown

Ah, it seems that Pages are not supported for subgroups: https://gitlab.com/gitlab-org/gitlab-ce/issues/30548

@Hiroki111

Copy link
Copy Markdown

I tried this approach, but it resulted in a 404 error.
The main javascript file (main..js) is missing on GitLab.
It works perfectly on my local machine.

Has anyone seen a similar issue?

@bgonzales12

Copy link
Copy Markdown

I'm not sure if this relates, but on GitHub pages it seems if the url is https://username.github.io/project it will not run the react app. However, if you add index.html to the end of the url it works.

@favasconcelos

Copy link
Copy Markdown

@CorruptedCode01 is this still reproducible? I'm not able to access even with index.html...

@mariogillazaro

mariogillazaro commented Nov 6, 2018

Copy link
Copy Markdown

I'm also trying this approach but get

[Error] Refused to execute https://azaroma.gitlab.io/static/js/main.fce1c1ef.js as a script because "X-Content-Type: nosniff" was given and its Content-Type is not a script MIME type.

and 404 for the script the css and the favicon

@AbhimanyuAryan

Copy link
Copy Markdown

@MeetPatel5

MeetPatel5 commented Jul 22, 2019

Copy link
Copy Markdown

check here how to deploy to Gitlab pages: https://www.gatsbyjs.org/docs/deploying-to-gitlab-pages/#deploying-to-gitlab-pages

@AbhimanyuAryan why you're telling irrelevant answer to the public. Understand the question first !

@edtz

edtz commented Oct 3, 2019

Copy link
Copy Markdown

This problem happens because CRA is not aware the URL is relative (because it's prefixed by project name). Adding "homepage": ".", to package.json will make it relative to index.html and fix the problem.

@scoobydoobeedoobeedoo

Copy link
Copy Markdown

This problem happens because CRA is not aware the URL is relative (because it's prefixed by project name). Adding "homepage": ".", to package.json will make it relative to index.html and fix the problem.

Thanks!

@eksecute

Copy link
Copy Markdown

This problem happens because CRA is not aware the URL is relative (because it's prefixed by project name). Adding "homepage": ".", to package.json will make it relative to index.html and fix the problem.

Totally saved me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment