forked from fyl080801/egg-vite-vue3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
fengyuanliang3
committed
Feb 25, 2021
0 parents
commit 71906f8
Showing
33 changed files
with
8,528 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
write: true, | ||
plugin: 'autod-egg', | ||
prefix: '^', | ||
devprefix: '^', | ||
exclude: [ | ||
'test/fixtures', | ||
'coverage', | ||
], | ||
dep: [ | ||
'egg', | ||
'egg-scripts', | ||
], | ||
devdep: [ | ||
'autod', | ||
'autod-egg', | ||
'egg-bin', | ||
'tslib', | ||
'typescript', | ||
], | ||
keep: [ | ||
], | ||
semver: [ | ||
], | ||
test: 'scripts', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
**/*.d.ts | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"extends": "eslint-config-egg/typescript", | ||
"parserOptions": { | ||
"project": "./tsconfig.json" | ||
}, | ||
"rules": { | ||
"array-bracket-spacing": "off", | ||
"space-before-function-paren": "off", | ||
"arrow-parens": "off", | ||
"comma-dangle": "off" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node | ||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions | ||
|
||
name: Node.js CI | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
branches: [ master ] | ||
schedule: | ||
- cron: '0 2 * * *' | ||
|
||
jobs: | ||
build: | ||
runs-on: ${{ matrix.os }} | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
node-version: [8] | ||
os: [ubuntu-latest, windows-latest, macos-latest] | ||
|
||
steps: | ||
- name: Checkout Git Source | ||
uses: actions/checkout@v2 | ||
|
||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
|
||
- name: Install Dependencies | ||
run: npm i -g npminstall && npminstall | ||
|
||
- name: Continuous Integration | ||
run: npm run ci | ||
|
||
- name: Code Coverage | ||
uses: codecov/codecov-action@v1 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
logs/ | ||
npm-debug.log | ||
node_modules/ | ||
coverage/ | ||
.idea/ | ||
run/ | ||
logs/ | ||
.DS_Store | ||
.vscode | ||
*.swp | ||
*.lock | ||
*.js | ||
!.autod.conf.js | ||
!yarn.lock | ||
|
||
app/**/*.js | ||
test/**/*.js | ||
config/**/*.js | ||
app/**/*.map | ||
test/**/*.map | ||
config/**/*.map |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
semi: true | ||
singleQuote: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
language: node_js | ||
node_js: | ||
- 'lts/*' | ||
before_install: | ||
- npm i npminstall -g | ||
install: | ||
- npminstall | ||
script: | ||
- npm run ci | ||
after_script: | ||
- npminstall codecov && codecov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# hackernews-async-ts | ||
|
||
[Hacker News](https://news.ycombinator.com/) showcase using typescript && egg | ||
|
||
## QuickStart | ||
|
||
### Development | ||
|
||
```bash | ||
$ npm i | ||
$ npm run dev | ||
$ open http://localhost:7001/ | ||
``` | ||
|
||
Don't tsc compile at development mode, if you had run `tsc` then you need to `npm run clean` before `npm run dev`. | ||
|
||
### Deploy | ||
|
||
```bash | ||
$ npm run tsc | ||
$ npm start | ||
``` | ||
|
||
### Npm Scripts | ||
|
||
- Use `npm run lint` to check code style | ||
- Use `npm test` to run unit test | ||
- se `npm run clean` to clean compiled js at development mode once | ||
|
||
### Requirement | ||
|
||
- Node.js 8.x | ||
- Typescript 2.8+ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Controller } from 'egg'; | ||
import { Route, HttpGet } from 'egg-decorator-router'; | ||
import { server } from '../middleware/vite'; | ||
|
||
@Route() | ||
export default class HomeController extends Controller { | ||
@HttpGet('/') | ||
public async index() { | ||
const renderData: any = {}; | ||
|
||
if (this.config.env === 'local') { | ||
const addressInfo: any = server?.httpServer?.address(); | ||
|
||
renderData.server = `${this.ctx.protocol}://${ | ||
addressInfo?.address === '::' ? 'localhost' : addressInfo?.address | ||
}:${addressInfo?.port}`; | ||
} | ||
|
||
await this.ctx.render('index.html', renderData); | ||
} | ||
|
||
@HttpGet('/api') | ||
public api() { | ||
const { ctx } = this; | ||
|
||
ctx.body = 'api'; | ||
} | ||
} | ||
|
||
// new Controller() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// import {} from 'egg'; | ||
|
||
import { EggMiddlewareFactory } from 'egg'; | ||
import { UserConfig, createServer, ViteDevServer } from 'vite'; | ||
|
||
export let server: ViteDevServer; | ||
|
||
const middleware: EggMiddlewareFactory = (options: UserConfig) => { | ||
return async (_ctx, next) => { | ||
if (!server) { | ||
server = await createServer({ | ||
...options, | ||
configFile: false, | ||
root: process.cwd(), | ||
// server: { port: options.server?.port || 8088 }, | ||
}); | ||
|
||
await server.listen(); | ||
|
||
_ctx.app.on('beforeClose', () => { | ||
server?.close(); | ||
}); | ||
} | ||
await next(); | ||
}; | ||
}; | ||
|
||
export default middleware; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Service } from 'egg'; | ||
|
||
/** | ||
* Test Service | ||
*/ | ||
export default class Test extends Service { | ||
|
||
/** | ||
* sayHi to you | ||
* @param name - your name | ||
*/ | ||
public async sayHi(name: string) { | ||
return `hi, ${name}`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!DOCTYPE html> | ||
<html lang=""> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
<meta name="viewport" content="width=device-width,initial-scale=1.0" /> | ||
</head> | ||
<body> | ||
<noscript> | ||
<strong> | ||
We're sorry but it doesn't work properly without JavaScript enabled. | ||
Please enable it to continue. | ||
</strong> | ||
</noscript> | ||
<div id="app"></div> | ||
<script type="module" src="{{server}}/client/main.ts"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
environment: | ||
matrix: | ||
- nodejs_version: '8' | ||
|
||
install: | ||
- ps: Install-Product node $env:nodejs_version | ||
- npm i npminstall && node_modules\.bin\npminstall | ||
|
||
test_script: | ||
- node --version | ||
- npm --version | ||
- npm run test | ||
|
||
build: off |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<template> | ||
<div> | ||
<Hello name="xxxxxx"></Hello> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import Hello from './components/Hello.vue'; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<template> | ||
<h1>Hello {{ props.name }} !!</h1> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import { defineProps } from 'vue'; | ||
const props = defineProps({ name: String }); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { createApp } from 'vue'; | ||
import App from './App.vue'; | ||
import 'vite/dynamic-import-polyfill'; | ||
|
||
createApp(App).mount('#app'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { EggAppConfig, EggAppInfo, PowerPartial } from 'egg'; | ||
|
||
export default (appInfo: EggAppInfo) => { | ||
const config = {} as PowerPartial<EggAppConfig>; | ||
|
||
// override config from framework / plugin | ||
// use for cookie sign key, should change to your own and keep security | ||
config.keys = appInfo.name + '_1614221169780_4319'; | ||
|
||
// add your egg config in here | ||
config.middleware = []; | ||
|
||
// add your special config in here | ||
const bizConfig = { | ||
sourceUrl: `https://github.com/eggjs/examples/tree/master/${appInfo.name}`, | ||
}; | ||
|
||
config.view = { | ||
defaultViewEngine: 'nunjucks', | ||
mapping: { | ||
'.html': 'nunjucks', | ||
}, | ||
}; | ||
|
||
// the return config will combines to EggAppConfig | ||
return { | ||
...config, | ||
...bizConfig, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { EggAppConfig, PowerPartial } from 'egg'; | ||
import { defineConfig } from 'vite'; | ||
import vue from '@vitejs/plugin-vue'; | ||
|
||
export default () => { | ||
const config: PowerPartial<EggAppConfig> = {}; | ||
|
||
config.middleware = ['vite']; | ||
|
||
config.vite = defineConfig({ | ||
build: { | ||
manifest: true, | ||
rollupOptions: { | ||
input: '/client/main.ts', | ||
}, | ||
}, | ||
plugins: [vue()], | ||
}); | ||
|
||
return config; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { EggAppConfig, PowerPartial } from 'egg'; | ||
|
||
export default () => { | ||
const config: PowerPartial<EggAppConfig> = {}; | ||
return config; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { EggPlugin } from 'egg'; | ||
|
||
const plugin: EggPlugin = { | ||
// static: true, | ||
nunjucks: { | ||
enable: true, | ||
package: 'egg-view-nunjucks', | ||
}, | ||
decoratorRouter: { | ||
enable: true, | ||
package: 'egg-decorator-router', | ||
}, | ||
}; | ||
|
||
export default plugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!DOCTYPE html> | ||
<html lang=""> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
<meta name="viewport" content="width=device-width,initial-scale=1.0" /> | ||
</head> | ||
<body> | ||
<noscript> | ||
<strong> | ||
We're sorry but it doesn't work properly without JavaScript enabled. | ||
Please enable it to continue. | ||
</strong> | ||
</noscript> | ||
<div id="app"></div> | ||
<script type="module" src="./client/main.ts"></script> | ||
</body> | ||
</html> |
Oops, something went wrong.