Skip to content

Commit

Permalink
feat: 添加按需导入完整导入demo示例
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoxian521 committed Oct 9, 2022
1 parent 0676f87 commit a3b9443
Show file tree
Hide file tree
Showing 21 changed files with 1,118 additions and 0 deletions.
14 changes: 14 additions & 0 deletions playgrounds/auto-import-demo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.vite-ssg-temp

node_modules
.DS_Store
dist
dist-ssr
*.local

# lock
yarn.lock
package-lock.json
pnpm-lock.yaml

*.log
2 changes: 2 additions & 0 deletions playgrounds/auto-import-demo/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
shamefully-hoist=true
strict-peer-dependencies=false
20 changes: 20 additions & 0 deletions playgrounds/auto-import-demo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## 按需导入示例

需要注意的是,[unplugin-vue-components](https://github.com/antfu/unplugin-vue-components) 实现自动引入 `element-plus` 的方式,在结合 [@pureadmin/descriptions](https://github.com/xiaoxian521/pure-admin-descriptions) 使用时,需要手动引入 `ElDescriptions` 样式,代码如下

```ts
// main.ts
import "element-plus/es/components/descriptions/style/css";
import "element-plus/es/components/descriptions-item/style/css";
```

`@pureadmin/descriptions` 内置 `element-plus``Loading` 动画,按需引入时还需要加上下面这些代码

```ts
// main.ts
import "element-plus/es/components/loading/style/css";

import { vLoading } from "element-plus";

app.directive("loading", vLoading);
```
21 changes: 21 additions & 0 deletions playgrounds/auto-import-demo/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Auto-Import-Demo</title>
<!-- element css cdn, if you use custom theme, remove it. -->
<!-- <link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/element-plus/dist/index.css"
/> -->
</head>

<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>

</html>
22 changes: 22 additions & 0 deletions playgrounds/auto-import-demo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "auto-import-demo",
"version": "1.1.1",
"scripts": {
"dev": "vite",
"serve": "vite",
"preview": "vite build && vite preview"
},
"dependencies": {
"@pureadmin/descriptions": "^1.1.1",
"element-plus": "^2.2.17",
"vue": "^3.2.40"
},
"devDependencies": {
"@types/node": "^18.8.3",
"@vitejs/plugin-vue": "^3.1.2",
"sass": "^1.55.0",
"typescript": "^4.8.4",
"unplugin-vue-components": "^0.22.8",
"vite": "^3.1.6"
}
}
1 change: 1 addition & 0 deletions playgrounds/auto-import-demo/public/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions playgrounds/auto-import-demo/src/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<template>
<PureDescriptions title="按需引入示例" :column="3" border :data="data" :columns="columns" :loading="loading" />
</template>

<script lang="ts" setup>
import { ref } from "vue"
const loading = ref({
load: true,
})
const columns = [{
label: "Name",
prop: "name",
}, {
label: "Phone",
prop: "phone",
}, {
label: "Place",
prop: "place",
}]
const data = ref([
{
name: "小明",
phone: "18100000000",
place: "China",
}
])
setTimeout(() => {
loading.value.load = false
}, 1000)
</script>

8 changes: 8 additions & 0 deletions playgrounds/auto-import-demo/src/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/// <reference types="vite/client" />

declare module "*.vue" {
import { DefineComponent } from "vue";
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
const component: DefineComponent<{}, {}, any>;
export default component;
}
15 changes: 15 additions & 0 deletions playgrounds/auto-import-demo/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { createApp } from "vue";
import App from "./App.vue";

// If you want to use ElDescriptions, import it.
import "element-plus/es/components/descriptions/style/css";
import "element-plus/es/components/descriptions-item/style/css";

import "element-plus/es/components/loading/style/css";

import { vLoading } from "element-plus";

import PureDescriptions from "@pureadmin/descriptions";

const app = createApp(App);
app.directive("loading", vLoading).use(PureDescriptions).mount("#app");
21 changes: 21 additions & 0 deletions playgrounds/auto-import-demo/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"compilerOptions": {
"baseUrl": ".",
"target": "esnext",
"useDefineForClassFields": true,
"module": "esnext",
"moduleResolution": "node",
"strict": true,
"jsx": "preserve",
"sourceMap": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"lib": ["esnext", "dom"],
"paths": {
"~/*": ["src/*"]
},
"skipLibCheck": true,
"types": ["@pureadmin/descriptions/volar"]
},
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"]
}
35 changes: 35 additions & 0 deletions playgrounds/auto-import-demo/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import path from "path";
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";

import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";

const pathSrc = path.resolve(__dirname, "src");

// https://vitejs.dev/config/
export default defineConfig({
resolve: {
alias: {
"~/": `${pathSrc}/`
}
},
server: {
host: "0.0.0.0"
},
plugins: [
vue(),
Components({
// allow auto load markdown components under `./src/components/`
extensions: ["vue", "md"],
// allow auto import and register components used in markdown
include: [/\.vue$/, /\.vue\?vue/, /\.md$/],
resolvers: [
ElementPlusResolver({
importStyle: "sass"
})
],
dts: "src/components.d.ts"
})
]
});
1 change: 1 addition & 0 deletions playgrounds/whole-import-demo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
## 完整导入示例
21 changes: 21 additions & 0 deletions playgrounds/whole-import-demo/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Whole-Import-Demo</title>
<!-- element css cdn, if you use custom theme, remove it. -->
<!-- <link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/element-plus/dist/index.css"
/> -->
</head>

<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>

</html>
21 changes: 21 additions & 0 deletions playgrounds/whole-import-demo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "whole-import-demo",
"version": "1.1.1",
"scripts": {
"dev": "vite",
"serve": "vite",
"preview": "vite build && vite preview"
},
"dependencies": {
"@pureadmin/descriptions": "^1.1.1",
"element-plus": "^2.2.17",
"vue": "^3.2.40"
},
"devDependencies": {
"@types/node": "^18.8.3",
"@vitejs/plugin-vue": "^3.1.2",
"sass": "^1.55.0",
"typescript": "^4.8.4",
"vite": "^3.1.6"
}
}
Loading

0 comments on commit a3b9443

Please sign in to comment.