Skip to content

Commit

Permalink
chore: use vite instead of nextjs in example (#88)
Browse files Browse the repository at this point in the history
* nextjs -> vite

* vite config
  • Loading branch information
seokju-na authored Jan 18, 2025
1 parent fb51506 commit c33cd34
Show file tree
Hide file tree
Showing 13 changed files with 724 additions and 320 deletions.
11 changes: 11 additions & 0 deletions example/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<title>react-thermal-printer example</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
5 changes: 0 additions & 5 deletions example/next-env.d.ts

This file was deleted.

35 changes: 0 additions & 35 deletions example/next.config.js

This file was deleted.

12 changes: 6 additions & 6 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
"name": "react-thermal-printer-exmaple",
"private": true,
"scripts": {
"dev": "next dev"
"dev": "vite dev"
},
"dependencies": {
"@tanstack/react-query": "^5.56.2",
"next": "14.2.13",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-thermal-printer": "workspace:^",
"typescript": "5.6.2"
"react-thermal-printer": "workspace:^"
},
"devDependencies": {
"@types/node": "^22",
"@types/react": "^18",
"@types/react-dom": "^18"
"@types/react-dom": "^18",
"@vitejs/plugin-react-swc": "^3.7.2",
"typescript": "5.6.2",
"vite": "^6.0.7"
}
}
11 changes: 0 additions & 11 deletions example/pages/_app.tsx

This file was deleted.

3 changes: 0 additions & 3 deletions example/pages/index.tsx

This file was deleted.

38 changes: 17 additions & 21 deletions example/src/IndexPage.tsx → example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { useMutation } from '@tanstack/react-query';
import { useState } from 'react';
import { Br, Cut, Line, Printer, Row, Text, render } from 'react-thermal-printer';

export function IndexPage() {
export function App() {
const receipt = (
<Printer type="epson" width={42} characterSet="korea" debug={true}>
<Text size={{ width: 2, height: 2 }}>9,500원</Text>
Expand Down Expand Up @@ -42,31 +41,28 @@ export function IndexPage() {
);

const [port, setPort] = useState<SerialPort>();
const { mutateAsync: print, isPending: isPrinting } = useMutation({
mutationFn: async () => {
let _port = port;
if (_port == null) {
_port = await navigator.serial.requestPort();
await _port.open({ baudRate: 9600 });
setPort(_port);
}
const print = async () => {
let _port = port;
if (_port == null) {
_port = await navigator.serial.requestPort();
await _port.open({ baudRate: 9600 });
setPort(_port);
}

const writer = _port.writable?.getWriter();
if (writer != null) {
const data = await render(receipt);

await writer.write(data);
writer.releaseLock();
}
},
});
const writer = _port.writable?.getWriter();
if (writer != null) {
const data = await render(receipt);
await writer.write(data);
writer.releaseLock();
}
};

return (
<main>
<div>{receipt}</div>
<div style={{ marginTop: 24 }}>
<button type="button" disabled={isPrinting} onClick={() => print()}>
{isPrinting ? '프린트 중...' : '프린트'}
<button type="button" onClick={print}>
Print
</button>
</div>
</main>
Expand Down
5 changes: 5 additions & 0 deletions example/src/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { createRoot } from 'react-dom/client';
import { App } from './App';

const root = createRoot(document.getElementById('root')!);
root.render(<App />);
3 changes: 0 additions & 3 deletions example/src/queryClient.ts

This file was deleted.

7 changes: 1 addition & 6 deletions example/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"incremental": true,
"isolatedModules": true,
"jsx": "preserve"
},
"include": [
"next-env.d.ts",
"vite-env.d.ts",
"**/*.ts",
"**/*.tsx"
],
Expand Down
1 change: 1 addition & 0 deletions example/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
6 changes: 6 additions & 0 deletions example/vite.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import react from '@vitejs/plugin-react-swc';
import { defineConfig } from 'vitest/config';

export default defineConfig({
plugins: [react() as any],
});
Loading

0 comments on commit c33cd34

Please sign in to comment.