@gx-design-vue/create-gx-cli 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +22 -0
  3. package/bin/create-gx-cli +4 -0
  4. package/package.json +31 -0
  5. package/src/cli.js +78 -0
  6. package/src/main.js +75 -0
  7. package/template-mobile-ts/.editorconfig +19 -0
  8. package/template-mobile-ts/.env.development +19 -0
  9. package/template-mobile-ts/.env.pro +19 -0
  10. package/template-mobile-ts/.env.production +19 -0
  11. package/template-mobile-ts/.eslintignore +16 -0
  12. package/template-mobile-ts/.eslintrc.js +64 -0
  13. package/template-mobile-ts/.prettierignore +9 -0
  14. package/template-mobile-ts/.stylelintignore +3 -0
  15. package/template-mobile-ts/README.md +16 -0
  16. package/template-mobile-ts/build/cdn.ts +5 -0
  17. package/template-mobile-ts/build/optimizer.ts +18 -0
  18. package/template-mobile-ts/build/plugin/autoImport.ts +26 -0
  19. package/template-mobile-ts/build/plugin/html.ts +26 -0
  20. package/template-mobile-ts/build/plugin/index.ts +38 -0
  21. package/template-mobile-ts/build/plugin/mock.ts +20 -0
  22. package/template-mobile-ts/index.html +24 -0
  23. package/template-mobile-ts/mock/_createProductionServer.ts +19 -0
  24. package/template-mobile-ts/mock/api/index.ts +66 -0
  25. package/template-mobile-ts/mock/utils.ts +9 -0
  26. package/template-mobile-ts/package.json +57 -0
  27. package/template-mobile-ts/pnpm-lock.yaml +3890 -0
  28. package/template-mobile-ts/postcss.config.js +11 -0
  29. package/template-mobile-ts/prettier.config.js +18 -0
  30. package/template-mobile-ts/public/favicon.ico +0 -0
  31. package/template-mobile-ts/public/js/flexible.js +44 -0
  32. package/template-mobile-ts/src/App.vue +5 -0
  33. package/template-mobile-ts/src/components/PageContainer/ProSkeleton.tsx +30 -0
  34. package/template-mobile-ts/src/components/PageContainer/index.tsx +113 -0
  35. package/template-mobile-ts/src/components/PageContainer/style.module.less +14 -0
  36. package/template-mobile-ts/src/core/gx-design/index.ts +7 -0
  37. package/template-mobile-ts/src/core/index.ts +12 -0
  38. package/template-mobile-ts/src/core/vant-design/index.ts +9 -0
  39. package/template-mobile-ts/src/design/index.less +3 -0
  40. package/template-mobile-ts/src/design/reset.less +155 -0
  41. package/template-mobile-ts/src/design/root.less +3 -0
  42. package/template-mobile-ts/src/design/vant.less +2 -0
  43. package/template-mobile-ts/src/global.less +1 -0
  44. package/template-mobile-ts/src/hooks/web/index.ts +5 -0
  45. package/template-mobile-ts/src/hooks/web/usePageLoading.ts +58 -0
  46. package/template-mobile-ts/src/layout/BasicLayout.vue +16 -0
  47. package/template-mobile-ts/src/layout/basicLayout.less +11 -0
  48. package/template-mobile-ts/src/main.ts +25 -0
  49. package/template-mobile-ts/src/router/index.ts +25 -0
  50. package/template-mobile-ts/src/router/routes.ts +20 -0
  51. package/template-mobile-ts/src/router/typings.ts +8 -0
  52. package/template-mobile-ts/src/services/index.ts +31 -0
  53. package/template-mobile-ts/src/store/index.ts +17 -0
  54. package/template-mobile-ts/src/store/modules/global.ts +33 -0
  55. package/template-mobile-ts/src/utils/cryptoJS.ts +25 -0
  56. package/template-mobile-ts/src/utils/index.ts +52 -0
  57. package/template-mobile-ts/src/utils/pageTitle.ts +12 -0
  58. package/template-mobile-ts/src/utils/request.ts +105 -0
  59. package/template-mobile-ts/src/utils/util.ts +32 -0
  60. package/template-mobile-ts/src/utils/validate.ts +292 -0
  61. package/template-mobile-ts/src/views/home.vue +82 -0
  62. package/template-mobile-ts/stylelint.config.js +106 -0
  63. package/template-mobile-ts/tsconfig.json +43 -0
  64. package/template-mobile-ts/types/auto-imports.d.ts +61 -0
  65. package/template-mobile-ts/types/components.d.ts +17 -0
  66. package/template-mobile-ts/types/global.d.ts +20 -0
  67. package/template-mobile-ts/types/gx-components.d.ts +13 -0
  68. package/template-mobile-ts/types/module.d.ts +9 -0
  69. package/template-mobile-ts/types/response.d.ts +12 -0
  70. package/template-mobile-ts/vite.config.ts +100 -0
  71. package/template-vue-ts/.vscode/extensions.json +3 -0
  72. package/template-vue-ts/README.md +18 -0
  73. package/template-vue-ts/index.html +13 -0
  74. package/template-vue-ts/package.json +20 -0
  75. package/template-vue-ts/public/vite.svg +1 -0
  76. package/template-vue-ts/src/App.vue +30 -0
  77. package/template-vue-ts/src/assets/vue.svg +1 -0
  78. package/template-vue-ts/src/components/HelloWorld.vue +38 -0
  79. package/template-vue-ts/src/main.ts +5 -0
  80. package/template-vue-ts/src/style.css +81 -0
  81. package/template-vue-ts/src/vite-env.d.ts +1 -0
  82. package/template-vue-ts/tsconfig.json +18 -0
  83. package/template-vue-ts/tsconfig.node.json +9 -0
  84. package/template-vue-ts/vite.config.ts +7 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 gx12358
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.
package/README.md ADDED
@@ -0,0 +1,22 @@
1
+ # `@dkundel/create-project`
2
+
3
+ 🏗 Personal CLI to bootstrap new projects
4
+
5
+ ## Installation & Usage
6
+
7
+ ```bash
8
+ npm init @dkundel/project
9
+ # or
10
+ npx @dkundel/create-project
11
+ # or
12
+ npm install -g @dkundel/create-project
13
+ create-project
14
+ ```
15
+
16
+ ## License
17
+
18
+ MIT
19
+
20
+ ## Collaborators
21
+
22
+ - Dominik Kundel <hi@dominik.dev>
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+
3
+ require = require('esm')(module /*, options*/);
4
+ require('../src/cli.js').cli();
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@gx-design-vue/create-gx-cli",
3
+ "version": "0.0.1",
4
+ "license": "MIT",
5
+ "description": "a cli to bootstrap gx project",
6
+ "main": "src/index.js",
7
+ "bin": "bin/create-gx-cli",
8
+ "publishConfig": {
9
+ "access": "public"
10
+ },
11
+ "keywords": [
12
+ "gx-cli",
13
+ "create-project"
14
+ ],
15
+ "author": "gx12358",
16
+ "dependencies": {
17
+ "chalk": "^2.4.2",
18
+ "esm": "^3.2.18",
19
+ "inquirer": "^6.2.2",
20
+ "kolorist": "^1.6.0",
21
+ "listr": "^0.14.3",
22
+ "minimist": "^1.2.7",
23
+ "ncp": "^2.0.0",
24
+ "prompts": "^2.4.2"
25
+ },
26
+ "files": [
27
+ "bin/",
28
+ "src/",
29
+ "template-*"
30
+ ]
31
+ }
package/src/cli.js ADDED
@@ -0,0 +1,78 @@
1
+ import minimist from 'minimist'
2
+ import prompts from 'prompts'
3
+ import { blue, reset, yellow } from 'kolorist'
4
+ import { createProject } from './main'
5
+
6
+ const defaultTargetDir = 'gx-cli-project'
7
+
8
+ const FRAMEWORKS = [
9
+ {
10
+ name: 'vue',
11
+ color: yellow
12
+ },
13
+ {
14
+ name: 'mobile',
15
+ color: blue
16
+ }
17
+ ]
18
+
19
+ const TEMPLATES = FRAMEWORKS.map(
20
+ (f) => (f.variants && f.variants.map((v) => v.name)) || [f.name]
21
+ ).reduce((a, b) => a.concat(b), [])
22
+
23
+ function formatTargetDir(targetDir) {
24
+ return targetDir ? targetDir.trim().replace(/\/+$/g, '') : ''
25
+ }
26
+
27
+ function parseArgumentsIntoOptions() {
28
+ const argv = minimist(process.argv.slice(2), { string: ['_'] })
29
+ const argTargetDir = formatTargetDir(argv._[0])
30
+ const argTemplate = argv.template || argv.t
31
+ return {
32
+ template: argTemplate,
33
+ projectName: argTargetDir
34
+ }
35
+ }
36
+
37
+ async function promptForMissingOptions(options) {
38
+ const answers = await prompts([
39
+ {
40
+ type: options.projectName ? null : 'text',
41
+ name: 'projectName',
42
+ message: reset('Project name:'),
43
+ initial: defaultTargetDir,
44
+ },
45
+ {
46
+ type: options.template && TEMPLATES.includes(options.template) ? null : 'select',
47
+ name: 'template',
48
+ message:
49
+ typeof options.template === 'string' && !TEMPLATES.includes(options.template)
50
+ ? reset(
51
+ `"${options.template}" isn't a valid template. Please choose from below: `,
52
+ )
53
+ : reset('Select a framework:'),
54
+ choices: FRAMEWORKS.map((framework) => {
55
+ const frameworkColor = framework.color
56
+ return {
57
+ title: frameworkColor(framework.name),
58
+ value: framework
59
+ }
60
+ }),
61
+ default: 'vue'
62
+ }
63
+ ])
64
+
65
+ return {
66
+ ...options,
67
+ template: options.template || answers.template ? answers.template.name : '',
68
+ projectName: options.projectName || answers.projectName || ''
69
+ }
70
+ }
71
+
72
+ export async function cli() {
73
+ let options = parseArgumentsIntoOptions()
74
+ options = await promptForMissingOptions(options)
75
+ if (options.template && options.projectName) {
76
+ await createProject(options)
77
+ }
78
+ }
package/src/main.js ADDED
@@ -0,0 +1,75 @@
1
+ import chalk from 'chalk'
2
+ import fs from 'fs'
3
+ import { fileURLToPath } from 'url'
4
+ import Listr from 'listr'
5
+ import ncp from 'ncp'
6
+ import path from 'path'
7
+ import { promisify } from 'util'
8
+
9
+ const access = promisify(fs.access)
10
+ const copy = promisify(ncp)
11
+ const writeFileSync = promisify(fs.writeFileSync)
12
+
13
+ async function copyTemplateFiles(templateDir, root) {
14
+ return copy(templateDir, root, {
15
+ clobber: false
16
+ })
17
+ }
18
+
19
+ function writeFile(path, content) {
20
+ writeFileSync(path, content)
21
+ }
22
+
23
+ export async function createProject(options) {
24
+ const cwd = process.cwd()
25
+
26
+ const root = path.join(cwd, options.projectName)
27
+
28
+ const getProjectName = () =>
29
+ options.projectName === '.' ? path.basename(path.resolve()) : options.projectName
30
+
31
+ const templateDir = path.resolve(
32
+ fileURLToPath(import.meta.url),
33
+ '../..',
34
+ `template-${options.template}-ts`
35
+ )
36
+
37
+ const pkg = JSON.parse(
38
+ fs.readFileSync(path.join(templateDir, `package.json`), 'utf-8')
39
+ )
40
+
41
+ pkg.name = options.projectName || getProjectName()
42
+
43
+ try {
44
+ await access(templateDir, fs.constants.R_OK)
45
+ } catch (err) {
46
+ console.error('%s Invalid template name', chalk.red.bold('ERROR'))
47
+ process.exit(1)
48
+ }
49
+
50
+ const tasks = new Listr(
51
+ [
52
+ {
53
+ title: 'Copy Project Files',
54
+ task: () => copyTemplateFiles(templateDir, root)
55
+ },
56
+ {
57
+ title: 'Edit Project package.json',
58
+ task: () => writeFile(path.join(root, 'package.json'), JSON.stringify(pkg, null, 2))
59
+ }
60
+ ],
61
+ {
62
+ exitOnError: false
63
+ }
64
+ )
65
+
66
+ await tasks.run()
67
+ console.log(`\nDone. Now run:\n`)
68
+ if (root !== cwd) {
69
+ console.log(`cd ${path.relative(cwd, root)}`)
70
+ }
71
+ console.log(`pnpm(yarn、npm) install`)
72
+ console.log(`pnpm(yarn、npm) run dev`)
73
+ console.log()
74
+ return true
75
+ }
@@ -0,0 +1,19 @@
1
+ root = true
2
+
3
+ [*]
4
+ charset=utf-8
5
+ end_of_line=lf
6
+ insert_final_newline=true
7
+ indent_style=space
8
+ indent_size=2
9
+ max_line_length = 100
10
+
11
+ [*.{yml,yaml,json}]
12
+ indent_style = space
13
+ indent_size = 2
14
+
15
+ [*.md]
16
+ trim_trailing_whitespace = false
17
+
18
+ [Makefile]
19
+ indent_style = tab
@@ -0,0 +1,19 @@
1
+ # 实际执行环境 development
2
+ VITE_NODE_ENV= development
3
+
4
+ # environment 代码环境
5
+ VITE_USE_MODE = development
6
+
7
+ VITE_USE_CDN= false
8
+
9
+ # 是否开启mock
10
+ VITE_USE_MOCK = true
11
+
12
+ # 是否使用v-console
13
+ VITE_USE_V_CONSOLE = false
14
+
15
+ # 是否删除console
16
+ VITE_DROP_CONSOLE = false
17
+
18
+ # api前缀
19
+ VITE_BASE_URL=/mock-server
@@ -0,0 +1,19 @@
1
+ # 实际执行环境 production
2
+ VITE_NODE_ENV= production
3
+
4
+ # environment 代码环境
5
+ VITE_USE_MODE = production
6
+
7
+ VITE_USE_CDN= false
8
+
9
+ # 是否使用v-console
10
+ VITE_USE_V_CONSOLE = false
11
+
12
+ # 是否开启mock
13
+ VITE_USE_MOCK = false
14
+
15
+ # 是否删除console
16
+ VITE_DROP_CONSOLE = true
17
+
18
+ # api前缀
19
+ VITE_BASE_URL=/mock-server
@@ -0,0 +1,19 @@
1
+ # 实际执行环境 production
2
+ VITE_NODE_ENV= test
3
+
4
+ # environment 代码环境
5
+ VITE_USE_MODE = test
6
+
7
+ VITE_USE_CDN= false
8
+
9
+ # 是否使用v-console
10
+ VITE_USE_V_CONSOLE = true
11
+
12
+ # 是否开启mock
13
+ VITE_USE_MOCK = true
14
+
15
+ # 是否删除console
16
+ VITE_DROP_CONSOLE = true
17
+
18
+ # api前缀
19
+ VITE_BASE_URL=/mock-server
@@ -0,0 +1,16 @@
1
+
2
+ *.sh
3
+ node_modules
4
+ *.md
5
+ *.woff
6
+ *.ttf
7
+ .vscode
8
+ .idea
9
+ dist
10
+ /public
11
+ /docs
12
+ .husky
13
+ .local
14
+ .history
15
+ /bin
16
+ Dockerfile
@@ -0,0 +1,64 @@
1
+ module.exports = {
2
+ root: true,
3
+ env: {
4
+ browser: true,
5
+ node: true,
6
+ es6: true,
7
+ },
8
+ parser: 'vue-eslint-parser',
9
+ parserOptions: {
10
+ parser: '@typescript-eslint/parser',
11
+ ecmaVersion: 2020,
12
+ sourceType: 'module',
13
+ jsxPragma: 'React',
14
+ ecmaFeatures: {
15
+ jsx: true,
16
+ },
17
+ },
18
+ extends: [
19
+ 'plugin:vue/vue3-recommended',
20
+ 'plugin:@typescript-eslint/recommended'
21
+ ],
22
+ rules: {
23
+ 'vue/script-setup-uses-vars': 'error',
24
+ '@typescript-eslint/ban-ts-ignore': 'off',
25
+ '@typescript-eslint/explicit-function-return-type': 'off',
26
+ '@typescript-eslint/no-explicit-any': 'off',
27
+ '@typescript-eslint/no-var-requires': 'off',
28
+ '@typescript-eslint/no-empty-function': 'off',
29
+ 'vue/custom-event-name-casing': 'off',
30
+ 'no-use-before-define': 'off',
31
+ '@typescript-eslint/no-use-before-define': 'off',
32
+ '@typescript-eslint/ban-ts-comment': 'off',
33
+ '@typescript-eslint/ban-types': 'off',
34
+ '@typescript-eslint/no-non-null-assertion': 'off',
35
+ '@typescript-eslint/explicit-module-boundary-types': 'off',
36
+ '@typescript-eslint/no-unused-vars': [
37
+ 'error',
38
+ {
39
+ argsIgnorePattern: '^_',
40
+ varsIgnorePattern: '^_',
41
+ },
42
+ ],
43
+ 'no-unused-vars': [
44
+ 'error',
45
+ {
46
+ argsIgnorePattern: '^_',
47
+ varsIgnorePattern: '^_',
48
+ },
49
+ ],
50
+ 'space-before-function-paren': 'off',
51
+
52
+ 'vue/attributes-order': 'off',
53
+ 'vue/one-component-per-file': 'off',
54
+ 'vue/html-closing-bracket-newline': 'off',
55
+ 'vue/max-attributes-per-line': 'off',
56
+ 'vue/multiline-html-element-content-newline': 'off',
57
+ 'vue/singleline-html-element-content-newline': 'off',
58
+ 'vue/attribute-hyphenation': 'off',
59
+ 'vue/require-default-prop': 'off',
60
+ 'vue/require-explicit-emits': 'off',
61
+ 'vue/html-self-closing': 0,
62
+ 'vue/multi-word-component-names': 'off',
63
+ },
64
+ };
@@ -0,0 +1,9 @@
1
+ /dist/*
2
+ .local
3
+ .output.js
4
+ /node_modules/**
5
+
6
+ **/*.svg
7
+ **/*.sh
8
+
9
+ /public/*
@@ -0,0 +1,3 @@
1
+ /dist/*
2
+ /public/*
3
+ public/*
@@ -0,0 +1,16 @@
1
+ # Vue 3 + TypeScript + Vite
2
+
3
+ This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
4
+
5
+ ## Recommended IDE Setup
6
+
7
+ - [VS Code](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar)
8
+
9
+ ## Type Support For `.vue` Imports in TS
10
+
11
+ Since TypeScript cannot handle type information for `.vue` imports, they are shimmed to be a generic Vue component type by default. In most cases this is fine if you don't really care about component prop types outside of templates. However, if you wish to get actual prop types in `.vue` imports (for example to get props validation when using manual `h(...)` calls), you can enable Volar's Take Over mode by following these steps:
12
+
13
+ 1. Run `Extensions: Show Built-in Extensions` from VS Code's command palette, look for `TypeScript and JavaScript Language Features`, then right click and select `Disable (Workspace)`. By default, Take Over mode will enable itself if the default TypeScript extension is disabled.
14
+ 2. Reload the VS Code window by running `Developer: Reload Window` from the command palette.
15
+
16
+ You can learn more about Take Over mode [here](https://github.com/johnsoncodehk/volar/discussions/471).
@@ -0,0 +1,5 @@
1
+ const css = []
2
+
3
+ const js = []
4
+
5
+ export const cdnConf = { css, js }
@@ -0,0 +1,18 @@
1
+ import type { GetManualChunk } from 'rollup'
2
+
3
+ const vendorLibs: { match: string[]; output: string }[] = [
4
+ {
5
+ match: ['vant'],
6
+ output: 'vant',
7
+ }
8
+ ]
9
+
10
+ export const configManualChunk: GetManualChunk = (id: string) => {
11
+ if (/[\\/]node_modules[\\/]/.test(id)) {
12
+ const matchItem = vendorLibs.find((item) => {
13
+ const reg = new RegExp(`[\\/]node_modules[\\/]_?(${item.match.join('|')})(.*)`, 'ig')
14
+ return reg.test(id)
15
+ })
16
+ return matchItem ? matchItem.output : null
17
+ }
18
+ }
@@ -0,0 +1,26 @@
1
+ import autoImport from 'unplugin-auto-import/vite'
2
+ import Components from 'unplugin-vue-components/vite'
3
+ import { VantResolver } from 'unplugin-vue-components/resolvers'
4
+
5
+ export function createAutoImport() {
6
+ return [
7
+ autoImport({
8
+ include: [
9
+ /\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
10
+ /\.vue$/, /\.vue\?vue/, // .vue
11
+ /\.md$/, // .md
12
+ ],
13
+ imports: [
14
+ 'vue',
15
+ 'vue-router'
16
+ ],
17
+ dts: 'types/auto-imports.d.ts'
18
+ }),
19
+ Components({
20
+ resolvers: [
21
+ VantResolver()
22
+ ],
23
+ dts: 'types/components.d.ts'
24
+ })
25
+ ]
26
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Plugin to minimize and use ejs template syntax in index.html.
3
+ * https://github.com/anncwb/vite-plugin-html
4
+ */
5
+ import { PluginOption } from 'vite'
6
+
7
+ import { createHtmlPlugin } from 'vite-plugin-html'
8
+
9
+ import { cdnConf } from '../cdn'
10
+
11
+ export function configHtmlPlugin(env: ViteEnv, isBuild: boolean) {
12
+
13
+ const htmlPlugin: PluginOption[] = createHtmlPlugin({
14
+ minify: isBuild,
15
+ inject: {
16
+ data: {
17
+ injectScript: env.VITE_USE_CDN ? cdnConf.js : [],
18
+ injectLink: env.VITE_USE_CDN ? cdnConf.css : [],
19
+ injectVlogScript: env.VITE_USE_V_CONSOLE
20
+ ? `<script src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js"></script><script>var vConsole = new window.VConsole();</script>`
21
+ : ''
22
+ }
23
+ }
24
+ })
25
+ return htmlPlugin
26
+ }
@@ -0,0 +1,38 @@
1
+ import type { Plugin, PluginOption } from 'vite'
2
+
3
+ import vue from '@vitejs/plugin-vue'
4
+ import vueJsx from '@vitejs/plugin-vue-jsx'
5
+
6
+ import vueSetupExtend from 'vite-plugin-vue-setup-extend'
7
+ import { configHtmlPlugin } from './html'
8
+ import { configMockPlugin } from './mock'
9
+ import { createAutoImport } from './autoImport'
10
+
11
+ export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean) {
12
+ const {
13
+ VITE_USE_V_CONSOLE,
14
+ VITE_USE_MOCK
15
+ } = viteEnv
16
+
17
+ const vitePlugins: (Plugin | PluginOption[])[] = [
18
+ // have to
19
+ vue(),
20
+ // have to
21
+ vueJsx()
22
+ ]
23
+
24
+ // vite-plugin-vue-setup-extend
25
+ vitePlugins.push(vueSetupExtend())
26
+
27
+ // vite-plugin-html
28
+ vitePlugins.push(configHtmlPlugin(viteEnv, isBuild))
29
+
30
+ // vite-plugin-mock
31
+ VITE_USE_MOCK && vitePlugins.push(configMockPlugin(isBuild))
32
+
33
+
34
+ // unplugin-auto-import/vite
35
+ vitePlugins.push(createAutoImport())
36
+
37
+ return vitePlugins
38
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Mock plugin for development and production.
3
+ * https://github.com/anncwb/vite-plugin-mock
4
+ */
5
+ import { viteMockServe } from 'vite-plugin-mock'
6
+
7
+ export function configMockPlugin(isBuild: boolean) {
8
+ return viteMockServe({
9
+ ignore: /^\_/,
10
+ mockPath: 'mock',
11
+ watchFiles: true,
12
+ localEnabled: !isBuild,
13
+ prodEnabled: isBuild,
14
+ injectCode: `
15
+ import { setupProdMockServer } from '../mock/_createProductionServer';
16
+
17
+ setupProdMockServer();
18
+ `
19
+ })
20
+ }
@@ -0,0 +1,24 @@
1
+ <!DOCTYPE html>
2
+ <html lang="zh">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <link rel="icon" href="/favicon.ico" type="image/x-icon" />
6
+ <meta
7
+ name="viewport"
8
+ content="width=device-width,viewport-fit=cover,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"
9
+ />
10
+ <title>vue-vant-mobile</title>
11
+ <% for (var i in injectLink) { %>
12
+ <link rel="stylesheet" type="text/css" href="<%= injectLink[i] %>" />
13
+ <% } %>
14
+ </head>
15
+ <body>
16
+ <div id="app"></div>
17
+ <% for (var i in injectScript) { %>
18
+ <script type="text/javascript" src="<%= injectScript[i] %>"></script>
19
+ <% } %>
20
+ <script type="module" src="/src/main.ts"></script>
21
+ <%- injectVlogScript %>
22
+ <script src="/js/flexible.js"></script>
23
+ </body>
24
+ </html>
@@ -0,0 +1,19 @@
1
+ import { createProdMockServer } from 'vite-plugin-mock/es/createProdMockServer'
2
+
3
+ const modules = import.meta.globEager('./api/*.ts')
4
+
5
+ const mockModules: any[] = []
6
+ Object.keys(modules).forEach((key) => {
7
+ if (key.includes('/_')) {
8
+ return
9
+ }
10
+ if (modules[key] && modules[key]['default']) mockModules.push(...modules[key]['default'])
11
+ return
12
+ })
13
+
14
+ /**
15
+ * Used in a production environment. Need to manually import all modules
16
+ */
17
+ export function setupProdMockServer() {
18
+ createProdMockServer(mockModules)
19
+ }