├── .commitlintrc.js ├── .cz-configrc.js ├── .github └── workflows │ ├── greetings.yml │ └── npm-publish.yml ├── .gitignore ├── .npmignore ├── LICENSE ├── README.md ├── examples └── vite-project │ ├── .gitignore │ ├── README.md │ ├── index.html │ ├── package.json │ ├── public │ └── favicon.ico │ ├── src │ ├── App.vue │ ├── assets │ │ └── logo.png │ ├── components │ │ └── HelloWorld.vue │ ├── main.ts │ └── shims-vue.d.ts │ ├── tsconfig.json │ └── vite.config.ts ├── package.json ├── src ├── index.ts └── lib │ ├── options.ts │ └── utils.ts └── tsconfig.json /.commitlintrc.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = { 4 | extends: ['@commitlint/config-conventional'], 5 | rules: { 6 | 'type-enum': [ 7 | 2, 8 | 'always', 9 | ['WIP', 'feat', 'fix', 'refactor', 'docs', 'test', 'style', 'chore', 'revert'], 10 | ], 11 | 'type-case': [1, 'always', ['lower-case', 'upper-case']], 12 | 'scope-case': [0, 'never'], 13 | 'subject-case': [0, 'never'], 14 | 'scope-empty': [0, 'never'], 15 | }, 16 | } 17 | -------------------------------------------------------------------------------- /.cz-configrc.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = { 4 | types: [ 5 | { 6 | value: 'WIP', 7 | name: '💪 WIP: Work in progress', 8 | }, 9 | { 10 | value: 'feat', 11 | name: '✨ feat: A new feature', 12 | }, 13 | { 14 | value: 'fix', 15 | name: '🐞 fix: A bug fix', 16 | }, 17 | { 18 | value: 'refactor', 19 | name: '🛠 refactor: A code change that neither fixes a bug nor adds a feature', 20 | }, 21 | { 22 | value: 'docs', 23 | name: '📚 docs: Documentation only changes', 24 | }, 25 | { 26 | value: 'test', 27 | name: '🏁 test: Add missing tests or correcting existing tests', 28 | }, 29 | { 30 | value: 'chore', 31 | name: 32 | "🗯 chore: Changes that don't modify src or test files. Such as updating build tasks, package manager", 33 | }, 34 | { 35 | value: 'style', 36 | name: 37 | '💅 style: Code Style, Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)', 38 | }, 39 | { 40 | value: 'revert', 41 | name: '⏪ revert: Revert to a commit', 42 | }, 43 | ], 44 | scopes: [], 45 | allowCustomScopes: true, 46 | allowBreakingChanges: ['feat', 'fix'], 47 | } 48 | -------------------------------------------------------------------------------- /.github/workflows/greetings.yml: -------------------------------------------------------------------------------- 1 | name: Greetings 2 | 3 | on: [pull_request, issues] 4 | 5 | jobs: 6 | greeting: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/first-interaction@v1 10 | with: 11 | repo-token: ${{ secrets.GITHUB_TOKEN }} 12 | issue-message: 'Thanks feedback. We will check it later:-)' 13 | pr-message: 'Thank for your PR. We will check it later:-)' 14 | -------------------------------------------------------------------------------- /.github/workflows/npm-publish.yml: -------------------------------------------------------------------------------- 1 | name: NPM-Publish 2 | 3 | on: 4 | push: 5 | # Sequence of patterns matched against refs/heads 6 | branches: 7 | # Push events on main branch 8 | - main 9 | 10 | pull_request: 11 | # Sequence of patterns matched against refs/heads 12 | branches: 13 | # Push events on main branch 14 | - main 15 | 16 | jobs: 17 | publish: 18 | runs-on: ubuntu-latest 19 | steps: 20 | - uses: actions/checkout@v1 21 | - uses: actions/setup-node@v1 22 | with: 23 | node-version: 12 24 | - run: yarn install 25 | - run: yarn test 26 | - uses: JS-DevTools/npm-publish@v1 27 | with: 28 | token: ${{ secrets.NPM_TOKEN }} 29 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | .npmrc 4 | 5 | # Log files 6 | npm-debug.log* 7 | yarn-debug.log* 8 | yarn-error.log* 9 | 10 | dist 11 | package-lock.json 12 | yarn.lock 13 | 14 | # Editor directories and files 15 | .idea 16 | .vscode 17 | *.suo 18 | *.ntvs* 19 | *.njsproj 20 | *.sln 21 | *.sw* 22 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | /examples 2 | yarn-error.log 3 | .github 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 PENG Rui 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vite-plugin-sleep 2 | 3 | > vite is too fast, we need to rest. a vite-plugin you never need. 4 | 5 |

6 | 7 | NPM Publish 8 | 9 | 10 | npm version 11 | 12 | 13 | License: MIT 14 | 15 |

16 | 17 | ## Motivation 18 | 19 | - In the old days with webpack, we had many times when we could compile with pay, and with vite it was so fast that we couldn't rest. 20 | - Time to take a nap in the vite. 21 | 22 | ## Usage 23 | 24 | ```sh 25 | yarn add vite-plugin-sleep 26 | ``` 27 | 28 | ```ts 29 | // vite.config.ts 30 | import sleep from 'vite-plugin-sleep' 31 | 32 | /** @see {@link https://vitejs.dev/config/} */ 33 | export default defineConfig({ 34 | plugins: [ 35 | // ...other plugins 36 | sleep(/* options */), 37 | ], 38 | }) 39 | ``` 40 | 41 | ## Options 42 | 43 | ```ts 44 | { 45 | /** 46 | * DevServer start delay(ms) 47 | * @default 20000 48 | */ 49 | devServerStartDelay: number 50 | /** 51 | * HMR delay(ms) 52 | * @default 3000 53 | */ 54 | hmrDelay: number 55 | } 56 | -------------------------------------------------------------------------------- /examples/vite-project/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store 3 | dist 4 | dist-ssr 5 | *.local 6 | -------------------------------------------------------------------------------- /examples/vite-project/README.md: -------------------------------------------------------------------------------- 1 | # Vue 3 + Typescript + Vite 2 | 3 | This template should help get you started developing with Vue 3 and Typescript in Vite. 4 | 5 | ## Recommended IDE Setup 6 | 7 | [VSCode](https://code.visualstudio.com/) + [Vetur](https://marketplace.visualstudio.com/items?itemName=octref.vetur). Make sure to enable `vetur.experimental.templateInterpolationService` in settings! 8 | 9 | ### If Using ` 12 | 13 | 14 | -------------------------------------------------------------------------------- /examples/vite-project/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vite-project", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "dev": "vite --open", 6 | "build": "vue-tsc --noEmit && vite build", 7 | "serve": "vite preview" 8 | }, 9 | "dependencies": { 10 | "vite-plugin-html-template": "1.0.0", 11 | "vue": "^3.0.5" 12 | }, 13 | "devDependencies": { 14 | "@vitejs/plugin-vue": "^1.2.1", 15 | "@vue/compiler-sfc": "^3.0.5", 16 | "typescript": "^4.1.3", 17 | "vite": "2.2.4", 18 | "vue-tsc": "^0.0.15" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /examples/vite-project/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IndexXuan/vite-plugin-sleep/7141eea85aec67aaca99d497ebb834318c8f1da5/examples/vite-project/public/favicon.ico -------------------------------------------------------------------------------- /examples/vite-project/src/App.vue: -------------------------------------------------------------------------------- 1 | 5 | 6 | 17 | 18 | 28 | -------------------------------------------------------------------------------- /examples/vite-project/src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IndexXuan/vite-plugin-sleep/7141eea85aec67aaca99d497ebb834318c8f1da5/examples/vite-project/src/assets/logo.png -------------------------------------------------------------------------------- /examples/vite-project/src/components/HelloWorld.vue: -------------------------------------------------------------------------------- 1 | 31 | 32 | 48 | 49 | 66 | -------------------------------------------------------------------------------- /examples/vite-project/src/main.ts: -------------------------------------------------------------------------------- 1 | import { createApp } from 'vue' 2 | import App from './App.vue' 3 | 4 | createApp(App).mount('#app') 5 | -------------------------------------------------------------------------------- /examples/vite-project/src/shims-vue.d.ts: -------------------------------------------------------------------------------- 1 | declare module '*.vue' { 2 | import { DefineComponent } from 'vue' 3 | const component: DefineComponent<{}, {}, any> 4 | export default component 5 | } 6 | -------------------------------------------------------------------------------- /examples/vite-project/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "esnext", 4 | "module": "esnext", 5 | "moduleResolution": "node", 6 | "strict": true, 7 | "jsx": "preserve", 8 | "sourceMap": true, 9 | "resolveJsonModule": true, 10 | "esModuleInterop": true, 11 | "lib": ["esnext", "dom"], 12 | "types": ["vite/client"] 13 | }, 14 | "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"] 15 | } 16 | -------------------------------------------------------------------------------- /examples/vite-project/vite.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite' 2 | import vue from '@vitejs/plugin-vue' 3 | import sleep from '../../src/index' 4 | 5 | // https://vitejs.dev/config/ 6 | export default defineConfig({ 7 | plugins: [vue(), sleep()], 8 | }) 9 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vite-plugin-sleep", 3 | "version": "0.0.1-never.1", 4 | "description": "vite plugin you never need", 5 | "main": "dist/index.js", 6 | "types": "dist/index.d.ts", 7 | "files": [ 8 | "dist" 9 | ], 10 | "author": "indexxuan@gmail.com", 11 | "scripts": { 12 | "commit": "git cz", 13 | "build": "tsup src/index.ts --dts", 14 | "lint": "prettier --write --parser typescript \"src/**/*.ts\"", 15 | "test": "echo missing test", 16 | "prepublishOnly": "npm run build" 17 | }, 18 | "license": "MIT", 19 | "homepage": "https://github.com/IndexXuan/vite-plugin-sleep", 20 | "repository": { 21 | "type": "git", 22 | "url": "git@github.com:IndexXuan/vite-plugin-sleep.git" 23 | }, 24 | "keywords": [ 25 | "vite-plugin", 26 | "slow HMR", 27 | "never use", 28 | "useless" 29 | ], 30 | "devDependencies": { 31 | "lint-staged": "10.5.4", 32 | "prettier": "2.2.1", 33 | "tsup": "3.12.1", 34 | "typescript": "4.1.3", 35 | "vite": "2.2.4", 36 | "@commitlint/cli": "7.2.0", 37 | "@commitlint/config-conventional": "7.1.2", 38 | "commitizen": "2.10.1", 39 | "cz-customizable": "5.2.0", 40 | "yorkie": "2.0.0" 41 | }, 42 | "prettier": { 43 | "printWidth": 100, 44 | "tabWidth": 2, 45 | "useTabs": false, 46 | "semi": false, 47 | "singleQuote": true, 48 | "jsxSingleQuote": false, 49 | "trailingComma": "all", 50 | "bracketSpacing": true, 51 | "jsxBracketSameLine": false, 52 | "arrowParens": "avoid" 53 | }, 54 | "config": { 55 | "commitizen": { 56 | "path": "./node_modules/cz-customizable" 57 | }, 58 | "cz-customizable": { 59 | "config": ".cz-configrc.js" 60 | } 61 | }, 62 | "gitHooks": { 63 | "pre-commit": "lint-staged", 64 | "commit-msg": "commitlint -e $GIT_PARAMS" 65 | }, 66 | "lint-staged": { 67 | "**/**.{ts,js,json}": [ 68 | "prettier --write" 69 | ] 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import type { Plugin } from 'vite' 2 | import type { UserOptions } from './lib/options' 3 | import { sleep } from './lib/utils' 4 | import { name } from '../package.json' 5 | 6 | export default function sleepPlugin(userOptions: UserOptions = {}): Plugin { 7 | const options = { 8 | ...userOptions, 9 | } 10 | let firstStart = true 11 | return { 12 | name, 13 | enforce: 'pre', 14 | configureServer(server) { 15 | server.middlewares.use(async (req, __, next) => { 16 | // if not html, next it. 17 | // @ts-expect-error 18 | if (!req.url.endsWith('.html') && req.url !== '/') { 19 | return next() 20 | } 21 | if (firstStart) { 22 | await sleep(options.devServerStartDelay || 20000) 23 | firstStart = false 24 | } 25 | next() 26 | }) 27 | }, 28 | async load() { 29 | await sleep(options.hmrDelay || 2000) 30 | return null 31 | }, 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/lib/options.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Sleep Plugin options. 3 | */ 4 | 5 | export interface SleepOptions { 6 | /** 7 | * DevServer start delay(ms) 8 | * @default 20000 9 | */ 10 | devServerStartDelay: number 11 | /** 12 | * HMR delay(ms) 13 | * @default 3000 14 | */ 15 | hmrDelay: number 16 | } 17 | 18 | export type UserOptions = Partial 19 | -------------------------------------------------------------------------------- /src/lib/utils.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * sleep 3 | */ 4 | export function sleep(delay: number) { 5 | return new Promise(resolve => setTimeout(resolve, delay)) 6 | } 7 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "esnext", 4 | "module": "esnext", 5 | "strict": true, 6 | "noUnusedLocals": true, 7 | "moduleResolution": "node", 8 | "declaration": true, 9 | "emitDeclarationOnly": true, 10 | "esModuleInterop": true, 11 | "resolveJsonModule": true, 12 | "forceConsistentCasingInFileNames": true, 13 | "noImplicitAny": true, 14 | "outDir": "dist", 15 | "lib": ["esnext"], 16 | "sourceMap": true 17 | }, 18 | "include": ["./src"], 19 | "exclude": ["node_modules"] 20 | } 21 | --------------------------------------------------------------------------------