|
| 1 | +# Vue REPL Playground |
| 2 | + |
| 3 | +Optimize `test/main` to support dynamically adding scenario validations for the REPL. Use `npm run dev:playground` to try it out. |
| 4 | + |
| 5 | +## Playground Architecture |
| 6 | + |
| 7 | +### Directory Structure |
| 8 | + |
| 9 | +``` |
| 10 | +playground/ |
| 11 | +├── index.html # HTML entry file with scenario switcher |
| 12 | +├── vite.config.ts # Standalone Vite config |
| 13 | +├── vite-plugin-scenario.js # Parse scenarios directory and generate REPL configuration |
| 14 | +├── scenarios/ # Scenario directory, add dynamically |
| 15 | +│ ├── basic/ # Basic example |
| 16 | +│ ├── customMain/ # Custom main entry |
| 17 | +│ ├── pinia/ # Pinia state management example |
| 18 | +│ └── vueRouter/ # Vue Router example |
| 19 | +└── src/ |
| 20 | + └── App.vue # Main application component |
| 21 | +``` |
| 22 | + |
| 23 | +### How It Works |
| 24 | + |
| 25 | +The playground uses a directory-based scenario system, where each scenario is an independent folder under `scenarios/`. Core features include: |
| 26 | + |
| 27 | +- **Virtual Module System**: A Vite plugin scans the scenario directory and generates a virtual module `virtual:playground-files` |
| 28 | +- **Dynamic Scenario Loading**: Users can switch scenarios via the UI, which automatically loads the corresponding configuration |
| 29 | + |
| 30 | +### Scenario Structure |
| 31 | + |
| 32 | +Each scenario directory typically contains the following files: |
| 33 | + |
| 34 | +``` |
| 35 | +scenarios/example-scenario/ |
| 36 | +├── App.vue # Main component |
| 37 | +├── main.ts # Entry file |
| 38 | +├── import-map.json # Dependency mapping |
| 39 | +├── tsconfig.json # TypeScript config |
| 40 | +└── _meta.js # Metadata config for REPL settings |
| 41 | +``` |
| 42 | + |
| 43 | +The `_meta.js` file exports the scenario configuration: |
| 44 | + |
| 45 | +```javascript |
| 46 | +export default { |
| 47 | + mainFile: 'main.ts', // Specify the main entry file |
| 48 | +} |
| 49 | +``` |
| 50 | + |
| 51 | +## Usage Example |
| 52 | + |
| 53 | +### Start the Playground |
| 54 | + |
| 55 | +```bash |
| 56 | +# Enter the project directory |
| 57 | +cd vue-repl |
| 58 | + |
| 59 | +# Install dependencies |
| 60 | +npm install |
| 61 | + |
| 62 | +# Start the development server |
| 63 | +npm run playground |
| 64 | +``` |
| 65 | + |
| 66 | +Visit the displayed local address (usually http://localhost:5174/) to use the playground. |
| 67 | + |
| 68 | +### Add a New Scenario |
| 69 | + |
| 70 | +1. Create a new folder under the `scenarios/` directory, e.g. `myScenario` |
| 71 | +2. Add the required files: |
| 72 | + |
| 73 | + ``` |
| 74 | + myScenario/ |
| 75 | + ├── App.vue # Main component |
| 76 | + ├── main.ts # Entry file (default entry) |
| 77 | + ├── import-map.json # Dependency config |
| 78 | + ├── tsconfig.json # TypeScript config |
| 79 | + └── _meta.js # Config with mainFile: 'main.ts' |
| 80 | + ``` |
| 81 | + |
| 82 | +3. Refresh the browser, and the new scenario will automatically appear in the dropdown menu. |
0 commit comments