Skip to content

Commit

Permalink
refactor/Made script which fix url in dist/index.html
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Kluge Svendsrud authored and Andreas Kluge Svendsrud committed Sep 11, 2024
1 parent b759b46 commit 29a6e56
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name: Deploy to GitHub Pages

on:
push:
branches:
- main
workflow_run:
workflows: ["Run ESLint Linter"]
types:
- completed

jobs:
build:
Expand Down
15 changes: 15 additions & 0 deletions fix-paths.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { readFile, writeFile } from 'fs/promises';
import path from 'path';

const filePath = path.join(process.cwd(), 'dist/index.html');

try {
const data = await readFile(filePath, 'utf8');

const result = data.replace(/\/assets\//g, './assets/');

await writeFile(filePath, result, 'utf8');
console.log('Successfully updated index.html paths!');
} catch (err) {
console.error('Error processing index.html:', err);
}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "module",
"scripts": {
"dev": "vite",
"build": "run-p type-check \"build-only {@}\" --",
"build": "npm run type-check && npm run build-only && node fix-paths.js",
"preview": "vite preview",
"test:unit": "vitest",
"build-only": "vite build",
Expand Down

0 comments on commit 29a6e56

Please sign in to comment.