Skip to content

Commit

Permalink
Merge branch 'main' into docs/#7/ci-script
Browse files Browse the repository at this point in the history
  • Loading branch information
wuzoo authored Sep 10, 2024
2 parents b7f4e9c + 582f5b0 commit eda66c5
Show file tree
Hide file tree
Showing 56 changed files with 386 additions and 6 deletions.
38 changes: 38 additions & 0 deletions generateIconExport.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const fs = require("fs");
const path = require("path");

// 파스칼 케이스 변환 함수
function toPascalCase(fileName) {
return fileName.replace(/(^\w|_\w)/g, (match) =>
match.replace("_", "").toUpperCase()
);
}

// index.ts 파일 생성 함수
function generateIndex() {
const svgDir = path.join(__dirname, "src", "assets", "svgs"); // SVG 파일들이 있는 디렉토리 경로
const outputFile = path.join(svgDir, "index.ts"); // 생성할 index.ts 경로

// SVG 디렉토리에서 파일 목록 가져오기
const files = fs
.readdirSync(svgDir)
.filter((file) => file.endsWith(".svg")) // .svg 파일만 필터링
.map((file) => ({
fileName: file,
pascalName: toPascalCase(path.basename(file, ".svg")), // 확장자 제거 후 파스칼 케이스로 변환
}));

// index.ts 파일 내용 작성
const exportStatements = files
.map(({ fileName, pascalName }) => {
return `export { default as ${pascalName} } from "./${fileName}";`;
})
.join("\n");

// index.ts 파일 덮어쓰기
fs.writeFileSync(outputFile, exportStatements);

// console.log(`index.ts generated with ${files.length} exports.`);
}

generateIndex();
27 changes: 24 additions & 3 deletions next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,30 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
webpack(config) {
// SVG imports를 처리하는 기존 규칙 가져오기
const fileLoaderRule = config.module.rules.find((rule) => rule.test?.test?.('.svg'));

import { createVanillaExtractPlugin } from "@vanilla-extract/next-plugin";
config.module.rules.push(
// svg imports 중 ?url로 끝나는 것에 대해서만 기존 규칙을 재적용
{
...fileLoaderRule,
test: /\.svg$/i,
resourceQuery: /url/, // *.svg?url
},
// *.svg imports를 React 컴포넌트로 변환
{
test: /\.svg$/i,
issuer: fileLoaderRule.issuer,
resourceQuery: { not: [...fileLoaderRule.resourceQuery.not, /url/] }, // exclude if *.svg?url
use: ['@svgr/webpack'],
},
);

const withVanillaExtract = createVanillaExtractPlugin();
// 처리가 완료된 *.svg를 무시하도록 파일 로더 규칙을 수정
fileLoaderRule.exclude = /\.svg$/i;

const nextConfig = {};
return config;
},
};

export default withVanillaExtract(nextConfig);
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"lint": "biome lint",
"typecheck": "tsc --noEmit",
"check": "concurrently \"pnpm lint\" \"pnpm typecheck\""
"generate-icon-export": "node ./generateIconExport.js"
},
"dependencies": {
"@vanilla-extract/css": "^1.15.5",
Expand All @@ -18,6 +19,7 @@
"react-dom": "^18"
},
"devDependencies": {
"@svgr/webpack": "^8.1.0",
"@biomejs/biome": "1.8.3",
"@types/node": "^20",
"@types/react": "^18",
Expand All @@ -26,4 +28,4 @@
"concurrently": "^9.0.0",
"typescript": "^5"
}
}
}
21 changes: 20 additions & 1 deletion src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
import { IcnAlarm } from '@/assets/svgs';
import AlarmUrl from '@/assets/svgs/icn_alarm.svg?url';
import Image from 'next/image';

export default function Home() {
return <div className="text-purple">AlgoHub</div>;
return (
<div className="text-purple">
<IcnAlarm width={50} height={50} />
<Image width={50} height={50} src={AlarmUrl} alt='alarm' priority />
<img width={50} height={50} src={AlarmUrl.src} alt="alarm" />
<div
style={{
width: 50,
height: 50,
backgroundImage: `url(${AlarmUrl.src})`,
backgroundRepeat: 'no-repeat',
backgroundSize: 'cover',
}}
></div>
</div>
);
}
3 changes: 3 additions & 0 deletions src/assets/svgs/icn_active.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/assets/svgs/icn_alarm.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/assets/svgs/icn_bell_header.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/assets/svgs/icn_bell_tab.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/assets/svgs/icn_btn_arrow_down.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/assets/svgs/icn_btn_arrow_left.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/assets/svgs/icn_btn_arrow_right.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions src/assets/svgs/icn_btn_checkbox.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/assets/svgs/icn_btn_checkbox_fail.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions src/assets/svgs/icn_btn_delete_circle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/assets/svgs/icn_btn_delete_rect.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/assets/svgs/icn_btn_list.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/assets/svgs/icn_btn_next.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions src/assets/svgs/icn_btn_pin.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/assets/svgs/icn_btn_plus.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions src/assets/svgs/icn_btn_sort.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions src/assets/svgs/icn_calendar_table.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit eda66c5

Please sign in to comment.