├── .husky
├── .gitignore
├── commit-msg
├── pre-commit
└── common.sh
├── .commitlintrc.js
├── src
├── layouts
│ ├── headless.vue
│ └── default.vue
├── modules
│ ├── use-plugins.ts
│ ├── index.ts
│ └── global-components.ts
├── shims-vue.d.ts
├── App.vue
├── components
│ ├── Global
│ │ ├── ButtonTwo.vue
│ │ └── ButtonOne.vue
│ └── Navbar.vue
├── router
│ └── index.ts
├── assets
│ ├── vue-logo.svg
│ ├── vite-logo.svg
│ └── not-found.svg
├── pages
│ ├── news
│ │ └── _id.vue
│ ├── index.vue
│ └── about.vue
├── store
│ ├── modules
│ │ └── user.ts
│ └── index.ts
├── shims-tsx.d.ts
└── main.ts
├── .prettierrc
├── index.html
├── .gitignore
├── components.d.ts
├── tsconfig.json
├── LICENSE
├── windi.config.ts
├── .cz-config.js
├── .eslintrc.js
├── README.md
├── vite.config.ts
└── package.json
/.husky/.gitignore:
--------------------------------------------------------------------------------
1 | _
2 |
--------------------------------------------------------------------------------
/.commitlintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | extends: ['cz'],
3 | }
4 |
--------------------------------------------------------------------------------
/src/layouts/headless.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.husky/commit-msg:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | . "$(dirname "$0")/_/husky.sh"
3 | . "$(dirname "$0")/common.sh"
4 |
5 | yarn commitlint --edit "$1"
6 |
--------------------------------------------------------------------------------
/.husky/pre-commit:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | . "$(dirname "$0")/_/husky.sh"
3 | . "$(dirname "$0")/common.sh"
4 |
5 | yarn lint-staged --allow-empty "$1"
6 |
--------------------------------------------------------------------------------
/.prettierrc:
--------------------------------------------------------------------------------
1 | {
2 | "printWidth": 90,
3 | "semi": false,
4 | "singleQuote": true,
5 | "tabWidth": 2,
6 | "trailingComma": "es5",
7 | "proseWrap": "always",
8 | "endOfLine": "auto"
9 | }
10 |
--------------------------------------------------------------------------------
/.husky/common.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | command_exists () {
4 | command -v "$1" >/dev/null 2>&1
5 | }
6 |
7 | # Windows 10, Git Bash and Yarn workaround
8 | if command_exists winpty && test -t 1; then
9 | exec < /dev/tty
10 | fi
11 |
--------------------------------------------------------------------------------
/src/modules/use-plugins.ts:
--------------------------------------------------------------------------------
1 | import { VueConstructor } from 'vue'
2 | import * as ElementUI from 'element-ui'
3 | import 'element-ui/lib/theme-chalk/index.css'
4 | import 'element-ui/lib/theme-chalk/display.css'
5 |
6 | export default (app: VueConstructor) => {
7 | app.use(ElementUI)
8 | }
9 |
--------------------------------------------------------------------------------
/src/shims-vue.d.ts:
--------------------------------------------------------------------------------
1 | declare module '*.vue' {
2 | import Vue from 'vue'
3 | export default Vue
4 | }
5 |
6 | declare module '@vue/runtime-dom' {
7 | export * from '@vue/runtime-dom/dist/runtime-dom'
8 | export { defineComponent, PropType } from '@vue/composition-api'
9 | }
10 |
--------------------------------------------------------------------------------
/src/App.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
15 |
--------------------------------------------------------------------------------
/src/components/Global/ButtonTwo.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
14 |
--------------------------------------------------------------------------------
/src/components/Global/ButtonOne.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
15 |
--------------------------------------------------------------------------------
/src/layouts/default.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
17 |
--------------------------------------------------------------------------------
/src/router/index.ts:
--------------------------------------------------------------------------------
1 | import Vue from 'vue'
2 | import VueRouter from 'vue-router'
3 | import { setupLayouts } from 'virtual:generated-layouts'
4 | import generatedRoutes from 'virtual:generated-pages'
5 | Vue.use(VueRouter)
6 |
7 | const routes = setupLayouts(generatedRoutes)
8 |
9 | const router = new VueRouter({
10 | mode: 'history',
11 | routes,
12 | })
13 |
14 | export default router
15 |
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | Vite Vue2 TS
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/src/modules/index.ts:
--------------------------------------------------------------------------------
1 | import { VueConstructor } from 'vue'
2 | import { Store } from 'vuex'
3 | import Router from 'vue-router'
4 | import GlobalComponents from './global-components'
5 | import UsePlugins from './use-plugins'
6 |
7 | export interface ModuleProp {
8 | app: VueConstructor
9 | store: Store
10 | router: Router
11 | }
12 |
13 | export default ({ app, store, router }: ModuleProp) => {
14 | GlobalComponents(app)
15 | UsePlugins(app)
16 | }
17 |
--------------------------------------------------------------------------------
/src/assets/vue-logo.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules
3 | /dist
4 | dist.zip
5 | dist.rar
6 | /.nuxt
7 | .nuxt
8 | .nuxt/axios.js
9 | .history
10 | static/sw.js
11 | now.json
12 | mock
13 | build
14 | auto-imports.d.ts
15 | pnpm-lock.*
16 |
17 | # local env files
18 | .env.local
19 | .env.*.local
20 |
21 | # Log files
22 | npm-debug.log*
23 | yarn-debug.log*
24 | yarn-error.log*
25 |
26 | # Editor directories and files
27 | .idea
28 | .yarn.lock
29 | package-lock.json
30 | yarn.lock
31 | *.suo
32 | *.ntvs*
33 | *.njsproj
34 | *.sln
35 | *.sw*
36 |
--------------------------------------------------------------------------------
/src/modules/global-components.ts:
--------------------------------------------------------------------------------
1 | import { VueConstructor } from 'vue'
2 |
3 | interface FileModule {
4 | default: VueConstructor
5 | }
6 |
7 | export default (Vue: VueConstructor) => {
8 | // Auto import src/componenst/Global/**/*.vue
9 | const componentsContext = import.meta.globEager('../components/Global/**/*.vue')
10 | Object.keys(componentsContext).forEach((key: string) => {
11 | const componentConfig = componentsContext[key] as FileModule
12 | const comp = componentConfig.default
13 | Vue.component(comp.name, comp)
14 | })
15 | }
16 |
--------------------------------------------------------------------------------
/src/pages/news/_id.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 | go back
4 |
5 | dynamic route
6 |
7 |
8 |
9 |
10 | {
11 | meta: {
12 | layout: 'headless'
13 | }
14 | }
15 |
16 |
17 |
28 |
--------------------------------------------------------------------------------
/src/store/modules/user.ts:
--------------------------------------------------------------------------------
1 | interface IUserProp {
2 | name: string
3 | age: number
4 | }
5 |
6 | interface IState {
7 | user: IUserProp
8 | }
9 |
10 | const state = {
11 | user: {
12 | name: 'vite',
13 | age: 24,
14 | },
15 | }
16 |
17 | const getters = {
18 | userName(state: IState) {
19 | return state.user.name
20 | },
21 | }
22 |
23 | const mutations = {
24 | SET_USER(state: IState, value: IUserProp) {
25 | state.user = value
26 | },
27 | }
28 |
29 | const actions = {}
30 |
31 | export default {
32 | state,
33 | getters,
34 | actions,
35 | mutations,
36 | }
37 |
--------------------------------------------------------------------------------
/src/shims-tsx.d.ts:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-unused-vars */
2 | import Vue, { VNode } from 'vue'
3 |
4 | declare global {
5 | namespace JSX {
6 | // tslint:disable no-empty-interface
7 | interface Element extends VNode {}
8 | // tslint:disable no-empty-interface
9 | interface ElementClass extends Vue {}
10 | interface IntrinsicElements {
11 | [elem: string]: any
12 | }
13 | }
14 | }
15 |
16 | declare global {
17 | interface Window {
18 | Protocol: any
19 | }
20 | interface ImportMeta {
21 | env: Record
22 | globEager(globPath: string): Record
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/pages/index.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
Vite ⚡ - Vue2 - typescript starter template
4 |
5 | This starter template will help you to easily create a Vue2 application bundled by
6 | the lightning fast build tool called Vite.
7 |
8 |
9 | typescript support
10 | auto routing
11 | auto store
12 | global component auto import
13 | commit lint
14 | vueuse
15 | and
16 | vue composition-api for Vue2.
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/src/main.ts:
--------------------------------------------------------------------------------
1 | import Vue from 'vue'
2 | import VCA, { createApp, h } from '@vue/composition-api'
3 | import router from './router'
4 | import AddModules from './modules/index'
5 | import store from './store'
6 | import App from './App.vue'
7 |
8 | // windicss layers
9 | import 'virtual:windi-base.css'
10 | import 'virtual:windi-components.css'
11 | // windicss utilities should be the last style import
12 | import 'virtual:windi-utilities.css'
13 | // windicss devtools support (dev only)
14 | import 'virtual:windi-devtools'
15 |
16 | Vue.use(VCA)
17 |
18 | AddModules({ app: Vue, store, router })
19 |
20 | Vue.config.productionTip = false
21 |
22 | const app = createApp({
23 | router,
24 | store,
25 | render: () => h(App),
26 | })
27 |
28 | app.mount('#app')
29 |
--------------------------------------------------------------------------------
/src/pages/about.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
About: Vite ⚡ - Vue 2 starter template
6 |
7 | This starter template will help you to easily create a Vue2 application bundled
8 | by the lightning fast build tool called Vite. Besides Vite this template also
9 | provides typescript support, auto-route, auto store, vueuse and the vue
10 | composition-api for Vue2.
11 |
12 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/src/store/index.ts:
--------------------------------------------------------------------------------
1 | import Vue from 'vue'
2 | import Vuex, { ModuleTree, Module } from 'vuex'
3 |
4 | function getModules() {
5 | const components = import.meta.globEager('./modules/*.ts')
6 | return components
7 | }
8 |
9 | interface FileModule {
10 | default: object
11 | }
12 |
13 | const requireModules = getModules()
14 | const modules: ModuleTree> = {}
15 | Object.keys(requireModules).forEach((key: string) => {
16 | const moduleName = key.replace(/^\.\/(.*)\.\w+$/, '$1')
17 | const module = requireModules[key] as FileModule
18 | const storeModule = module.default || module
19 | modules[moduleName] = { ...storeModule, namespaced: true }
20 | })
21 |
22 | Vue.use(Vuex)
23 |
24 | const store = new Vuex.Store({
25 | modules: {
26 | ...modules,
27 | },
28 | })
29 |
30 | export default store
31 |
--------------------------------------------------------------------------------
/components.d.ts:
--------------------------------------------------------------------------------
1 | // generated by unplugin-vue-components
2 | // We suggest you to commit this file into source control
3 | // Read more: https://github.com/vuejs/vue-next/pull/3399
4 |
5 | declare module 'vue' {
6 | export interface GlobalComponents {
7 | ButtonOne: typeof import('./src/components/Global/ButtonOne.vue')['default']
8 | ButtonTwo: typeof import('./src/components/Global/ButtonTwo.vue')['default']
9 | ElButton: typeof import('element-ui/lib/button')['default']
10 | ElDivider: typeof import('element-ui/lib/divider')['default']
11 | ElMenu: typeof import('element-ui/lib/menu')['default']
12 | ElMenuItem: typeof import('element-ui/lib/menu-item')['default']
13 | ElTag: typeof import('element-ui/lib/tag')['default']
14 | Navbar: typeof import('./src/components/Navbar.vue')['default']
15 | }
16 | }
17 |
18 | export {}
19 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "esnext",
4 | "module": "esnext",
5 | "strict": true,
6 | "jsx": "preserve",
7 | "importHelpers": true,
8 | "moduleResolution": "node",
9 | "allowJs": true,
10 | "skipLibCheck": true,
11 | "esModuleInterop": true,
12 | "allowSyntheticDefaultImports": true,
13 | "sourceMap": true,
14 | "baseUrl": ".",
15 | "types": [
16 | "vite-plugin-vue-layouts/client",
17 | "vite-plugin-pages/client",
18 | "vite/client",
19 | "unplugin-vue2-script-setup/types"
20 | ],
21 | "paths": {
22 | "@/*": ["./src*"]
23 | },
24 | "lib": ["esnext", "dom", "dom.iterable", "scripthost"]
25 | },
26 | "include": ["**/*.ts", "**/*.tsx", "**/*.vue", "tests/**/*.ts", "tests/**/*.tsx"],
27 | "exclude": ["node_modules", "mock", "build", "dist"]
28 | }
29 |
--------------------------------------------------------------------------------
/src/components/Navbar.vue:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
16 |
35 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 han
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.
22 |
--------------------------------------------------------------------------------
/windi.config.ts:
--------------------------------------------------------------------------------
1 | import { defineConfig } from 'windicss/helpers'
2 | import colors from 'windicss/colors'
3 | import typography from 'windicss/plugin/typography'
4 |
5 | export default defineConfig({
6 | darkMode: 'class',
7 | // https://windicss.org/posts/v30.html#attributify-mode
8 | attributify: true,
9 |
10 | plugins: [typography()],
11 | theme: {
12 | extend: {
13 | typography: {
14 | DEFAULT: {
15 | css: {
16 | maxWidth: '65ch',
17 | color: 'inherit',
18 | a: {
19 | color: 'inherit',
20 | opacity: 0.75,
21 | fontWeight: '500',
22 | textDecoration: 'underline',
23 | '&:hover': {
24 | opacity: 1,
25 | color: colors.teal[600],
26 | },
27 | },
28 | b: { color: 'inherit' },
29 | strong: { color: 'inherit' },
30 | em: { color: 'inherit' },
31 | h1: { color: 'inherit' },
32 | h2: { color: 'inherit' },
33 | h3: { color: 'inherit' },
34 | h4: { color: 'inherit' },
35 | code: { color: 'inherit' },
36 | },
37 | },
38 | },
39 | },
40 | },
41 | })
42 |
--------------------------------------------------------------------------------
/.cz-config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | types: [
3 | { value: 'init', name: 'init: 初始提交' },
4 | { value: 'feat', name: 'feat: 增加新功能' },
5 | { value: 'fix', name: 'fix: 修复bug' },
6 | { value: 'ui', name: 'ui: 更新UI' },
7 | { value: 'refactor', name: 'refactor: 代码重构' },
8 | { value: 'release', name: 'release: 发布' },
9 | { value: 'deploy', name: 'deploy: 部署' },
10 | { value: 'docs', name: 'docs: 修改文档' },
11 | { value: 'test', name: 'test: 增删测试' },
12 | { value: 'chore', name: 'chore: 更改配置文件' },
13 | { value: 'style', name: 'style: 样式修改不影响逻辑' },
14 | { value: 'revert', name: 'revert: 版本回退' },
15 | { value: 'add', name: 'add: 添加依赖' },
16 | { value: 'minus', name: 'minus: 版本回退' },
17 | { value: 'del', name: 'del: 删除代码/文件' },
18 | ],
19 | scopes: [],
20 | messages: {
21 | type: '选择更改类型:\n',
22 | scope: '更改的范围:\n',
23 | // 如果allowcustomscopes为true,则使用
24 | // customScope: 'Denote the SCOPE of this change:',
25 | subject: '简短描述:\n',
26 | body: '详细描述. 使用"|"换行:\n',
27 | breaking: 'Breaking Changes列表:\n',
28 | footer: '关闭的issues列表. E.g.: #31, #34:\n',
29 | confirmCommit: '确认提交?',
30 | },
31 | allowCustomScopes: true,
32 | allowBreakingChanges: ['feat', 'fix'],
33 | }
34 |
--------------------------------------------------------------------------------
/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | root: true,
3 | env: {
4 | node: true,
5 | browser: true,
6 | },
7 | extends: [
8 | 'eslint:recommended',
9 | 'plugin:vue/recommended',
10 | '@vue/typescript/recommended',
11 | '@vue/prettier/@typescript-eslint',
12 | 'prettier',
13 | ],
14 | parserOptions: {
15 | ecmaVersion: 2020,
16 | },
17 | plugins: ['vue', 'prettier'],
18 | // add your custom rules here
19 | rules: {
20 | 'prettier/prettier': [
21 | 'error',
22 | {},
23 | {
24 | usePrettierrc: true,
25 | },
26 | ],
27 | 'prefer-const': 2,
28 | 'no-console': 'off',
29 | 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
30 | 'no-tabs': 'off',
31 | 'space-before-function-paren': 'off',
32 | 'no-unused-vars': ['error', { vars: 'all', args: 'none', ignoreRestSiblings: false }],
33 | 'vue/order-in-components': 'off',
34 | 'vue/no-v-html': 'off',
35 | 'vue/component-definition-name-casing': 'off',
36 | 'vue/attribute-hyphenation': 'off',
37 | '@typescript-eslint/explicit-module-boundary-types': 'off',
38 | '@typescript-eslint/ban-ts-comment': 'off',
39 | '@typescript-eslint/no-empty-function': 'off',
40 | '@typescript-eslint/no-this-alias': 'off',
41 | '@typescript-eslint/no-unused-vars': 'off',
42 | '@typescript-eslint/ban-types': 'off',
43 | },
44 | }
45 |
--------------------------------------------------------------------------------
/src/assets/vite-logo.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # vite-vue2-typescript
2 |
3 | Vite Vue2 typescript starter template using composition-api with Script Setup!
4 |
5 | ## Features
6 |
7 | - 🗂 [File based routing](./src/pages)
8 |
9 | - 📦 [Global Components auto importing](./src/components/Global)
10 |
11 | - 📑 [Layout system](./src/layouts)
12 |
13 | - 😃 [Script Setup](https://github.com/antfu/vue2-script-setup-transform)
14 |
15 | - 🎨 [Commitlint](./husky)
16 |
17 | - 🔥 TypeScript, of course
18 |
19 | ### Plugins
20 |
21 | - [`vue/compositon-api`](https://github.com/vuejs/composition-api) Composition API plugin for Vue 2
22 |
23 | - [`VueUse`](https://github.com/antfu/vueuse) - collection of useful composition APIs
24 |
25 | - [`vite-plugin-pages`](https://github.com/hannoeru/vite-plugin-pages) - file system based
26 | routing
27 |
28 | - [`vite-plugin-vue-layouts`](https://github.com/anncwb/vite-plugin-style-import) Vue layout plugin for Vite
29 |
30 | - [`vite-plugin-style-import`](https://github.com/anncwb/vite-plugin-style-import) A plug-in
31 | that imports component library styles on demand
32 |
33 | - [`vue2-helper`](https://github.com/ambit-tsai/vue2-helpers) - A util package to use Vue 2 with Composition API easily
34 |
35 |
36 | ## Usage
37 |
38 | ### Development
39 |
40 | Just run and visit http://localhost:3003
41 |
42 | ```bash
43 | yarn dev
44 | ```
45 |
46 | ## Commit lint
47 |
48 | This repo use `commitizen` , if run `git cz` has no effect, you might need to install commitizen global as `yarn add global commitizen` or `npm i -g commitizen`
49 |
50 | then use `git cz` to add commit information.
51 |
52 | At lint staged it will trigger eslint auto fix and use `pretty-quick` to format files.
53 |
54 | And enjoy!
55 |
56 | ### Thanks
57 |
58 | - [vitesse](https://github.com/antfu/vitesse) Opinionated Vite Starter Template
59 |
--------------------------------------------------------------------------------
/vite.config.ts:
--------------------------------------------------------------------------------
1 | import { resolve } from 'path'
2 | import { defineConfig } from 'vite'
3 | import Layouts from 'vite-plugin-vue-layouts'
4 | import Pages from 'vite-plugin-pages'
5 | import { createVuePlugin } from 'vite-plugin-vue2'
6 | import ScriptSetup from 'unplugin-vue2-script-setup/vite'
7 | import Inspect from 'vite-plugin-inspect'
8 | import OptimizationPersist from 'vite-plugin-optimize-persist'
9 | import PkgConfig from 'vite-plugin-package-config'
10 | import Components from 'unplugin-vue-components/vite'
11 | import { ElementUiResolver } from 'unplugin-vue-components/resolvers'
12 | import WindiCSS from 'vite-plugin-windicss'
13 |
14 | const rollupOptions = {}
15 |
16 | const alias = [
17 | { find: /^~/, replacement: '' },
18 | { find: 'vue', replacement: 'vue/dist/vue.esm' },
19 | {
20 | find: '@',
21 | replacement: resolve(__dirname, ''),
22 | },
23 | ]
24 |
25 | const proxy = {}
26 |
27 | const define = {
28 | 'process.env.NODE_ENV': '"development"',
29 | 'precess.env.SITE_NAME': '"Vite Vue2 App"',
30 | }
31 |
32 | const esbuild = {}
33 |
34 | // @see https://cn.vitejs.dev/config/
35 | export default defineConfig({
36 | base: './', // index.html文件所在位置
37 | root: './', // js导入的资源路径
38 | publicDir: 'static',
39 | resolve: {
40 | alias,
41 | extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue', '.styl'],
42 | dedupe: ['vue-demi'],
43 | },
44 | define: define,
45 | server: {
46 | // 代理
47 | proxy,
48 |
49 | port: 3003,
50 | fs: {
51 | strict: false,
52 | },
53 | },
54 | build: {
55 | target: 'es2015',
56 | minify: 'terser', // 是否进行压缩,boolean | 'terser' | 'esbuild',默认使用terser
57 | manifest: false, // 是否产出maifest.json
58 | sourcemap: false, // 是否产出soucemap.json
59 | outDir: 'build', // 产出目录
60 | rollupOptions,
61 | },
62 | esbuild,
63 | plugins: [
64 | createVuePlugin({
65 | jsx: true,
66 | vueTemplateOptions: {
67 | compilerOptions: {
68 | whitespace: 'condense',
69 | },
70 | },
71 | }),
72 | PkgConfig(),
73 | OptimizationPersist(),
74 | Components({
75 | resolvers: [ElementUiResolver()],
76 | include: [/\.vue$/, /\.vue\?vue/, /\.md$/],
77 | dts: true,
78 | }),
79 | Inspect(),
80 | ScriptSetup(),
81 | Layouts({
82 | layoutsDir: 'src/layouts',
83 | }),
84 | // https://github.com/hannoeru/vite-plugin-pages
85 | Pages({
86 | pagesDir: [{ dir: 'src/pages', baseRoute: '' }],
87 | exclude: ['**/components/**.vue'],
88 | extensions: ['vue'],
89 | syncIndex: false,
90 | replaceSquareBrackets: true,
91 | nuxtStyle: true,
92 | }),
93 | WindiCSS(),
94 | ],
95 | css: {
96 | preprocessorOptions: {},
97 | },
98 | })
99 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "vite-vue2-typescript",
3 | "private": true,
4 | "scripts": {
5 | "postinstall": "husky install",
6 | "dev": "vite",
7 | "build": "vite build",
8 | "lint": "eslint './src/**/*.{js,ts,tsx,vue,md}'",
9 | "lint:fix": "eslint './src/**/*.{js,ts,tsx,vue,md}' --fix",
10 | "format": "pretty-quick --staged --ignore-path .gitignore"
11 | },
12 | "dependencies": {
13 | "@vue/composition-api": "^1.0.0-rc.8",
14 | "@vueuse/core": "^4.9.1",
15 | "core-js": "^3.11.1",
16 | "element-ui": "^2.15.5",
17 | "vue": "^2.6.12",
18 | "vue-router": "^3.5.1",
19 | "vue2-helpers": "^1.1.3",
20 | "vuex": "^3.6.2"
21 | },
22 | "devDependencies": {
23 | "@commitlint/cli": "^13.1.0",
24 | "@commitlint/config-conventional": "^13.1.0",
25 | "@types/node": "^16.7.10",
26 | "@typescript-eslint/eslint-plugin": "^4.22.0",
27 | "@typescript-eslint/parser": "^4.22.0",
28 | "@vue/compiler-sfc": "^3.2.4",
29 | "@vue/eslint-config-prettier": "^6.0.0",
30 | "@vue/eslint-config-typescript": "^7.0.0",
31 | "@vue/runtime-dom": "^3.2.4",
32 | "commitlint-config-cz": "^0.13.2",
33 | "cz-customizable": "^6.3.0",
34 | "eslint": "^7.25.0",
35 | "eslint-config-prettier": "^8.3.0",
36 | "eslint-plugin-prettier": "^3.4.0",
37 | "eslint-plugin-vue": "^7.9.0",
38 | "husky": "^6.0.0",
39 | "lint-staged": "^11.1.2",
40 | "prettier": "^2.2.1",
41 | "pretty-quick": "^3.1.1",
42 | "typescript": "^4.3.5",
43 | "unplugin-vue-components": "^0.14.11",
44 | "unplugin-vue2-script-setup": "^0.4.2",
45 | "vite": "^2.2.3",
46 | "vite-plugin-inspect": "^0.2.2",
47 | "vite-plugin-optimize-persist": "^0.0.5",
48 | "vite-plugin-package-config": "^0.0.3",
49 | "vite-plugin-pages": "^0.17.4",
50 | "vite-plugin-style-import": "^1.1.1",
51 | "vite-plugin-vue-layouts": "^0.3.1",
52 | "vite-plugin-vue2": "^1.4.4",
53 | "vite-plugin-windicss": "^1.2.7",
54 | "vue-demi": "^0.7.5",
55 | "vue-template-compiler": "^2.6.14",
56 | "windicss": "^3.1.7"
57 | },
58 | "lint-staged": {
59 | "**/**.{js,json,vue,ts}": [
60 | "eslint --fix --ignore-path .gitignore",
61 | "pretty-quick --staged --ignore-path .gitignore"
62 | ]
63 | },
64 | "husky": {
65 | "hooks": {
66 | "pre-commit": "lint-staged"
67 | }
68 | },
69 | "config": {
70 | "commitizen": {
71 | "path": "node_modules/cz-customizable"
72 | },
73 | "cz-customizable": {
74 | "config": "./.cz-config.js"
75 | }
76 | },
77 | "vite": {
78 | "optimizeDeps": {
79 | "include": [
80 | "@vue/composition-api",
81 | "@vue/runtime-dom",
82 | "element-ui",
83 | "element-ui/lib/button",
84 | "element-ui/lib/divider",
85 | "element-ui/lib/menu",
86 | "element-ui/lib/menu-item",
87 | "element-ui/lib/tag",
88 | "vue",
89 | "vue-router",
90 | "vue2-helpers/vue-router",
91 | "vuex"
92 | ]
93 | }
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/src/assets/not-found.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------