javascript - How do you publish a typescript website to GitHub Pages using Visual Studio? - Stack Overflow

So I made a Typescript project with Visual Studio.It works fine when I launch it with Visual Studio,

So I made a Typescript project with Visual Studio. It works fine when I launch it with Visual Studio, but if I try to push it to my GitHub Pages site, it will put the index.html in a subfolder and I get a 404 error when I try to load my website. Even if I try to reference the index.html in the website url it doesn't really work.

I was wondering if it's possible to only publish the needed items. I think I would only need the subfolder. Correct me if I am wrong though.

Note: I have the GitHub extension for Visual Studio installed.

UPDATE:

Since some of the links don't seem to work anymore I think I should give some extra information. So basically you need to have a branch named gh-pages. On that branch you need to have an index.html file in your root folder. Then the index.html file should be visible on the github page URL.

So I made a Typescript project with Visual Studio. It works fine when I launch it with Visual Studio, but if I try to push it to my GitHub Pages site, it will put the index.html in a subfolder and I get a 404 error when I try to load my website. Even if I try to reference the index.html in the website url it doesn't really work.

I was wondering if it's possible to only publish the needed items. I think I would only need the subfolder. Correct me if I am wrong though.

Note: I have the GitHub extension for Visual Studio installed.

UPDATE:

Since some of the links don't seem to work anymore I think I should give some extra information. So basically you need to have a branch named gh-pages. On that branch you need to have an index.html file in your root folder. Then the index.html file should be visible on the github page URL.

Share Improve this question edited Jan 2, 2019 at 16:11 BuggStream asked Mar 20, 2016 at 8:28 BuggStreamBuggStream 932 silver badges6 bronze badges 1
  • It would be useful if you gave some context about how you attempt to publish, showing the specific mands you run, their output etc. – Martin Commented Mar 20, 2016 at 8:44
Add a ment  | 

2 Answers 2

Reset to default 2

You need to push a branch named gh-pages in order to view it as a website.

Create a new branch and then move the file into the root folder of the branch, upload it to the gh-pages and you set to go.

Check this out:

https://github./nirgeier/JimVliet.github.io/tree/gh-pages

This is how your file should be inside your root folder.

I wanted the main branch to be the one deployed to GitHub pages, every time I push to main, so I made an Action for this. I made it for vanilla TypeScript projects (no web frameworks).

I bined the static content action and since for npx tsc I needed node, the NextJS action, where I replaced the NextJS build step with:

- name: Build with Typescript
        run: npx tsc

Put it in .github/workflows as main.yml

# Simple workflow for deploying static content to GitHub Pages
name: Deploy static content to Pages

on:
  push:
    branches:
      - main
      
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
  contents: read
  pages: write
  id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to plete.
concurrency:
  group: "pages"
  cancel-in-progress: false

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Detect package manager
        id: detect-package-manager
        run: |
          if [ -f "${{ github.workspace }}/yarn.lock" ]; then
            echo "manager=yarn" >> $GITHUB_OUTPUT
            echo "mand=install" >> $GITHUB_OUTPUT
            exit 0
          elif [ -f "${{ github.workspace }}/package.json" ]; then
            echo "manager=npm" >> $GITHUB_OUTPUT
            echo "mand=ci" >> $GITHUB_OUTPUT
            exit 0
          else
            echo "Unable to determine package manager"
            exit 1
          fi
      - name: Setup Node
        uses: actions/setup-node@v4
        with:
          node-version: "20"
      - name: Setup Pages
        uses: actions/configure-pages@v5
      - name: Install dependencies
        run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.mand }}
      - name: Build with Typescript
        run: npx tsc
      - name: Upload artifact
        uses: actions/upload-pages-artifact@v3
        with:
          # Upload entire repository
          path: '.'
  deploy:
    environment:
       name: github-pages
       url: ${{ steps.deployment.outputs.page_url }}
    runs-on: ubuntu-latest
    needs: build
    steps:
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v4

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745599130a4635295.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信