Skip to content

Commit

Permalink
fix: github pages上で画像が読み込めないバグを修正
Browse files Browse the repository at this point in the history
  • Loading branch information
eteeeeeerminal committed Sep 9, 2021
1 parent de3d251 commit d305d9d
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/push-feature.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ jobs:
- run: npm run build
env:
CI: true
GITHUB_PAGES: true
- run: npm run lint
1 change: 1 addition & 0 deletions .github/workflows/push-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ jobs:
- run: npm run build
env:
CI: true
GITHUB_PAGES: true
- name: ビルド結果を GitHub Pages へ配置します。
uses: peaceiris/actions-gh-pages@v3
with:
Expand Down
15 changes: 14 additions & 1 deletion next.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
const localDomain = '';
const productDomain = 'https://virtualprogrammersnetwork.github.io';
const productPath = '/vpn-website';
const isProd = process.env.NODE_ENV === 'production';
const isCI = !!process.env.CI;
const path = isCI && isProd ? productPath : '';
const assetPrefix = (isCI && isProd ? productDomain : localDomain) + path;

/** @type {Partial<import('next/dist/next-server/server/config-shared').NextConfig>} */
const providedExports = { future: { strictPostcssConfiguration: true } };
const providedExports = {
assetPrefix,
basePath: path,
env: { assetPrefix },
future: { strictPostcssConfiguration: true },
};

/** @type {Partial<import('next/dist/next-server/server/config-shared').NextConfig>} */
module.exports = providedExports;
Expand Down
16 changes: 16 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"babel-plugin-macros": "^3.1.0",
"babel-plugin-twin": "^1.0.2",
"browserslist": "^4.16.6",
"dotenv": "^10.0.0",
"eslint": "^7.30.0",
"eslint-config-airbnb-typescript": "^12.3.1",
"eslint-config-next": "^11.0.1",
Expand Down
7 changes: 6 additions & 1 deletion src/components/image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ type Props = {
const Img = ({ src, alt, width, height }: Props): JSX.Element => {
return (
<picture>
<img src={src} alt={alt} width={width} height={height} />
<img
src={`${process.env.assetPrefix}${src}`}
alt={alt}
width={width}
height={height}
/>
</picture>
);
};
Expand Down

0 comments on commit d305d9d

Please sign in to comment.