├── .npmignore ├── .gitignore ├── tsconfig.json ├── package.json ├── README.md ├── LICENCE └── src └── index.ts /.npmignore: -------------------------------------------------------------------------------- 1 | .idea 2 | node_modules 3 | src -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | dist 2 | .idea 3 | node_modules 4 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "ESNext", 4 | "target": "es2017", 5 | "lib": ["ESNext", "DOM", "WebWorker"], 6 | "esModuleInterop": true, 7 | "strict": true, 8 | "strictNullChecks": true, 9 | "moduleResolution": "Node", 10 | "resolveJsonModule": true, 11 | "noUnusedLocals": true 12 | }, 13 | "exclude": [ 14 | "dist", 15 | "node_modules", 16 | "test" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vite-plugin-eruda", 3 | "version": "1.0.1", 4 | "main": "dist/index.js", 5 | "module": "dist/index.mjs", 6 | "types": "dist/index.d.ts", 7 | "files": [ 8 | "dist" 9 | ], 10 | "exports": { 11 | "import": "./dist/index.mjs", 12 | "require": "./dist/index.js" 13 | }, 14 | "scripts": { 15 | "build": "tsup src/index.ts --format cjs,esm --dts" 16 | }, 17 | "author": "wuxiuran", 18 | "license": "MIT", 19 | "devDependencies": { 20 | "tsup": "^4.11.2", 21 | "typescript": "^4.3.3", 22 | "vite": "^2.3.7" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Vite Plugin Eruda 2 | 3 | > A vite plugin help you automatically open debugging tools in the development environment 4 | 5 | ### Install 6 | ```sh 7 | $ yarn add vite-plugin-eruda 8 | ``` 9 | 10 | ### Usage 11 | ```javascript 12 | import eruda from 'vite-plugin-eruda' 13 | 14 | 15 | module.exports = { 16 | plugins: [ 17 | // others 18 | eruda() 19 | ] 20 | } 21 | ``` 22 | 23 | ### Options 24 | 25 | #### `debug` 26 | 27 | - **Type:** `boolean | undefind` 28 | - **Default:** `'undefind'` 29 | 30 | Optional. If not, process.env.node will be used by default `process.env.NODE_ENV !== "production"` standard opens the debugging mode. If there is, this parameter takes precedence. 31 | 32 | ### License 33 | MIT 34 | -------------------------------------------------------------------------------- /LICENCE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import type { IndexHtmlTransformResult, HtmlTagDescriptor } from 'vite' 2 | 3 | export default ({ 4 | debug 5 | } : { 6 | debug: boolean | undefined 7 | } = { 8 | debug: undefined 9 | }) => { 10 | return { 11 | name: 'vite-plugin-eruda', 12 | transformIndexHtml(html: string): IndexHtmlTransformResult { 13 | const tags: HtmlTagDescriptor[] = [ 14 | { 15 | tag: 'script', 16 | attrs: { 17 | src: 'https://cdn.jsdelivr.net/npm/eruda', 18 | }, 19 | injectTo: 'head', 20 | }, 21 | { 22 | tag: 'script', 23 | children: 'eruda.init();', 24 | injectTo: 'head', 25 | } 26 | ] 27 | if (debug === true) { 28 | return { 29 | html, 30 | tags 31 | } 32 | } else if (debug === false) { 33 | return html 34 | } 35 | // @ts-ignore 36 | if (process.env.NODE_ENV !== "production") { 37 | return { 38 | html, 39 | tags 40 | } 41 | } else { 42 | return html 43 | } 44 | } 45 | } 46 | } 47 | --------------------------------------------------------------------------------