workflow(sfc-playground): share and download buttons
This commit is contained in:
31
packages/sfc-playground/src/download/download.ts
Normal file
31
packages/sfc-playground/src/download/download.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { exportFiles } from '../store'
|
||||
import { saveAs } from 'file-saver'
|
||||
|
||||
import index from './template/index.html?raw'
|
||||
import main from './template/main.js?raw'
|
||||
import pkg from './template/package.json?raw'
|
||||
import config from './template/vite.config.js?raw'
|
||||
import readme from './template/README.md?raw'
|
||||
|
||||
export async function downloadProject() {
|
||||
const { default: JSZip } = await import('jszip')
|
||||
const zip = new JSZip()
|
||||
|
||||
// basic structure
|
||||
zip.file('index.html', index)
|
||||
zip.file('package.json', pkg)
|
||||
zip.file('vite.config.js', config)
|
||||
zip.file('README.md', readme)
|
||||
|
||||
// project src
|
||||
const src = zip.folder('src')!
|
||||
src.file('main.js', main)
|
||||
|
||||
const files = exportFiles()
|
||||
for (const file in files) {
|
||||
src.file(file, files[file])
|
||||
}
|
||||
|
||||
const blob = await zip.generateAsync({ type: 'blob' })
|
||||
saveAs(blob, 'vue-project.zip')
|
||||
}
|
||||
14
packages/sfc-playground/src/download/template/README.md
Normal file
14
packages/sfc-playground/src/download/template/README.md
Normal file
@@ -0,0 +1,14 @@
|
||||
# Vite Vue Starter
|
||||
|
||||
This is a project template using [Vite](https://vitejs.dev/). It requires [Node.js](https://nodejs.org) v12+.
|
||||
|
||||
To start:
|
||||
|
||||
```sh
|
||||
npm install
|
||||
npm run dev
|
||||
|
||||
# if using yarn:
|
||||
yarn
|
||||
yarn dev
|
||||
```
|
||||
13
packages/sfc-playground/src/download/template/index.html
Normal file
13
packages/sfc-playground/src/download/template/index.html
Normal file
@@ -0,0 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Vite App</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
4
packages/sfc-playground/src/download/template/main.js
Normal file
4
packages/sfc-playground/src/download/template/main.js
Normal file
@@ -0,0 +1,4 @@
|
||||
import { createApp } from 'vue'
|
||||
import App from './App.vue'
|
||||
|
||||
createApp(App).mount('#app')
|
||||
17
packages/sfc-playground/src/download/template/package.json
Normal file
17
packages/sfc-playground/src/download/template/package.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "vite-vue-starter",
|
||||
"version": "0.0.0",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"serve": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"vue": "^3.0.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vitejs/plugin-vue": "^1.1.5",
|
||||
"@vue/compiler-sfc": "^3.0.9",
|
||||
"vite": "^2.1.3"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [vue()]
|
||||
})
|
||||
Reference in New Issue
Block a user