Skip to content

Commit

Permalink
feat: add server for device detection
Browse files Browse the repository at this point in the history
  • Loading branch information
Sasan Farrokh committed Jul 1, 2021
1 parent 95a923a commit d3e9c9f
Show file tree
Hide file tree
Showing 23 changed files with 881 additions and 109 deletions.
5 changes: 4 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ module.exports = {
"@typescript-eslint"
],
"rules": {
"@typescript-eslint/no-non-null-assertion": "off"
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-explicit-any": "off",
"object-curly-spacing": ["error", "always"]
}
};
6 changes: 6 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
src
node_modules
examples
.vscode
.idea
.DS_Store
4 changes: 4 additions & 0 deletions bin/vmd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const vmd = require('../dist/index')

console.log(vmd.default)
vmd.default.createDevServer().listen(3000)
3 changes: 0 additions & 3 deletions device.d.ts

This file was deleted.

13 changes: 13 additions & 0 deletions examples/react-example/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="src/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
21 changes: 21 additions & 0 deletions examples/react-example/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "react-example",
"version": "0.0.0",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"serve": "vite preview"
},
"dependencies": {
"react": "^17.0.0",
"react-dom": "^17.0.0",
"vite-plugin-multi-device": "*"
},
"devDependencies": {
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"@vitejs/plugin-react-refresh": "^1.3.1",
"typescript": "^4.1.2",
"vite": "^2.1.5"
}
}
42 changes: 42 additions & 0 deletions examples/react-example/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
.App {
text-align: center;
}

.App-logo {
height: 40vmin;
pointer-events: none;
}

@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
}

.App-header {
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}

.App-link {
color: #61dafb;
}

@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}

button {
font-size: calc(10px + 2vmin);
}
48 changes: 48 additions & 0 deletions examples/react-example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React, { useState } from 'react'
import logo from './logo.svg'
import './App.css'

function App() {
const [count, setCount] = useState(0)

return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>Hello Vite + React! + MultiDevice</p>
<p>
<em>current device -> { window.DEVICE.desktop ? 'desktop' : 'mobile' }</em>
</p>
<p>
<button onClick={() => setCount((count) => count + 1)}>
count is: {count}
</button>
</p>
<p>
Edit <code>App.tsx</code> and save to test HMR updates.
</p>
<p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
{' | '}
<a
className="App-link"
href="https://vitejs.dev/guide/features.html"
target="_blank"
rel="noopener noreferrer"
>
Vite Docs
</a>
</p>
</header>
</div>
)
}

export default App
15 changes: 15 additions & 0 deletions examples/react-example/src/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions examples/react-example/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
"Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

code {
font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
monospace;
}
7 changes: 7 additions & 0 deletions examples/react-example/src/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions examples/react-example/src/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react'
import ReactDOM from 'react-dom'
import './index.css'
import App from './App'

ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
)
20 changes: 20 additions & 0 deletions examples/react-example/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"target": "ESNext",
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"types": ["vite/client"],
"allowJs": false,
"skipLibCheck": false,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "ESNext",
"moduleResolution": "Node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react"
},
"include": ["./src"]
}
8 changes: 8 additions & 0 deletions examples/react-example/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig } from 'vite'
import reactRefresh from '@vitejs/plugin-react-refresh'
import multiDevice from 'vite-plugin-multi-device';

// https://vitejs.dev/config/
export default defineConfig({
plugins: [reactRefresh(), multiDevice()]
})
1 change: 1 addition & 0 deletions loading.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
loading...
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@
},
"homepage": "https://github.com/SasanFarrokh/vite-plugin-multi-device/tree/master/#readme",
"scripts": {
"dev": "tsup src/index.ts --watch",
"build": "tsup src/index.ts --external debug --dts",
"dev": "tsup src/index.ts --external fsevents --watch",
"build": "tsup src/index.ts --external debug --external fsevents --dts",
"lint": "eslint --fix .",
"test": "jest",
"test:watch": "jest --watch",
"prepublishOnly": "npm run build"
},
"devDependencies": {
"@rollup/plugin-replace": "^2.4.2",
"@types/express": "^4.17.12",
"@types/jest": "^26.0.10",
"@types/node": "^14.6.0",
"@typescript-eslint/eslint-plugin": "^4.13.0",
Expand All @@ -34,5 +35,8 @@
"tsup": "^3.6.1",
"typescript": "^4.1.3",
"vite": "^2.3.8"
},
"dependencies": {
"express": "^4.17.1"
}
}
Loading

0 comments on commit d3e9c9f

Please sign in to comment.