Coder Social home page Coder Social logo

atqq / uni-vue3-ts-template Goto Github PK

View Code? Open in Web Editor NEW
233.0 12.0 63.0 428 KB

开箱即用的uni-app vue3 TS 工程化模板项目,支持小程序/H5/APP开发使用,包含pinia,sass/less,axios,vitest,eslint,Unocss

Home Page: https://uni.vue3.sugarat.top

License: MIT License

JavaScript 15.17% HTML 2.79% Vue 33.60% TypeScript 37.91% SCSS 10.34% Less 0.18%
uni-app typescript vue3

uni-vue3-ts-template's Introduction

uni-vue3-ts-template

uni-app Vue3 + TypeScript + Vite + Pinia + Unocss 模板项目

支持小程序,H5,App

图片

Unocss

H5 微信小程序 App(iOS) App(Android)
图片 图片 图片

其它模板

Env Suggest

Node >= 18

pnpm 8

Registry taobao - https://registry.npmmirror.com/

Use This Template

npx degit atqq/uni-vue3-ts-template#main my-uni-vue3-ts-vite-project

Feature

Prod

Dev

使用

安装依赖

建议使用pnpm,依赖安装速度更快

npm i -g pnpm
pnpm install

MAC M1(ARM芯片),其它操作系统无需关注,正常运行需要手动安装 esbuild-darwin-64即可

pnpm add @esbuild/[email protected] -D

安装的版本或者指令可以运行下面这个脚本获取

node arm-esbuild-version.js

# 或者
pnpm mac:m1:esbuild

本地启动

微信小程序

# 构建出产物
pnpm dev:mp-weixin

Q1: 如果dev的时候发现报错,可以尝试删除node_modules之后再在命令行中运行pnpm install --shamefully-hoist重新安装依赖再pnpm dev:mp-weixin

详细参考文档

Q2: 如果运行白屏,有报错信息 “app.js错误ReferenceError: regeneratorRuntime is not defined”

参考解决方案 给微信小程序IDE开启增强编译选项

然后将编译结果dist/dev/mp-weixin导入微信开发者工具即可运行

点击查看 导入详细步骤

图片

图片

图片

Q3:真机运行白屏,模拟器,开发环境都正常

参考issue 25,使用build 生产的资源进行真机调试就可以了

H5

# CSR
pnpm dev:h5

根据提示,打开对应地址即可访问

图片

App

Q1: 如启动到App侧有报错? 请更新至最新的HBuilderX-Alpha客户端

安装一些必要工具

需要使用 uni-app 官方提供的 HBuilderX 启动项目

Android模拟器在MacOSX、Windows上都可以安装;iOS模拟器只能在MacOSX上安装。

先安装相关模拟器,详细参考文档

准备就绪后,使用 HBuilderX 打开项目

iOS模拟器运行

通过顶部菜单栏,找到运行入口

图片

选择一个目标设备,点击启动即可

图片

Android模拟器运行

这里以夜神模拟器为例

点击查看 详细步骤

先通过 HBuilderX 修改模拟器端口为 62001

图片

打开夜神模拟器

图片

选择运行到 Android 基座

图片

选择已经打开的模拟器,点击运行即可 图片

图片

打包构建

微信小程序

pnpm build:mp-weixin

H5

# CSR
pnpm build:h5

App

基于 HBuilderX 参考官方文档进行进一步的操作

其它更多运行脚本 查看 package.json中的scripts

css预处理

已配置scssless全局变量

// vite.config.ts
export default defineConfig({
  // ......
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: '@import "@/static/styles/variables.scss";'
      },
      less: {
        additionalData: '@import "@/static/styles/variables.less";'
      }
    }
  }
})

additionalData的值是文件的路径,可以按照自己业务需求去修改,如果项目样式变量分的比较细,可以使用一个样式文件引入多个变量样式文件,然后在这里引入入口文件

别名配置

如果我们想要在import的时候 src 的路径简写成@,下面的就是配置 vite 的别名,属性类型请查看vite文档

  • @ 代替 ./src
  • @components代替./src/components
// vite.config.ts
export default defineConfig({
  // ......
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src'),
      '@components': path.resolve(__dirname, './src/components')
    }
  }
})

例子:

// pages/index/index.vue
- import Hello from '../../components/hello/index.vue'
+ import Hello from '@/components/hello/index.vue'
// 或者
+ import Hello from '@components/hello/index.vue'

ts

如果是使用ts开发,这样还不够,ts不会识别路径的别名,显示找不到模块的报错,这个时候需要修改 tsconfig.json 文件,纠正下路径才可以。

// tsconfig.json
{
  // ......
  "compilerOptions": {
    // ......
+    "baseUrl": "./",
+    "paths": {
+      "@/*": ["src/*"],
+      "@components/*": ["src/components/*"]
    }
  },
}

添加 baseUrlpaths 参数,就可以完美解决编辑器的报错提示了!

原子化css

支持小程序,h5,app

uni-vue3-ts-template's People

Contributors

atqq avatar itmier avatar mellowco avatar sunpm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

uni-vue3-ts-template's Issues

组件库选择

建议把组件库 从 vk-uview-ui 换成 tumi

tumi 是纯 vue3 的写法 ,使用的组合式api ;

vk-uview-ui 兼容 vue2 和 vue3 ,还是使用的 选项式 api ;

是否方便维护一个非TS分支?

感谢开源,谢谢
或者如果不想用 TS,除了把 .ts 语法改为 js 外,还需要哪些改动?我来改改然后提交个 PR 也可以

新版本编译报错

.pnpm/[email protected]_ppdxls77r7tfsxvxidunrbldv4/node_modules/vite/dist/node-cjs/publicUtils.cjs:64
11:10:41.068 const cache = options.cache ?? new SplitVendorChunkCache();
11:10:41.069 ^
11:10:41.072 SyntaxError: Unexpected token '?'
11:10:41.072 at wrapSafe (internal/modules/cjs/loader.js:915:16)
11:10:41.075 at Module._compile (internal/modules/cjs/loader.js:963:27)
11:10:41.078 at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
11:10:41.082 at Module.load (internal/modules/cjs/loader.js:863:32)
11:10:41.082 at Function.Module._load (internal/modules/cjs/loader.js:708:14)
11:10:41.085 at Module.require (internal/modules/cjs/loader.js:887:19)
11:10:41.088 at require (internal/modules/cjs/helpers.js:74:18)
11:10:41.091 at Object. (/Users/lvxiang/work_place/demo/test/uni-vue3-ts-template/node_modules/.pnpm/[email protected]_ppdxls77r7tfsxvxidunrbldv4/node_modules/vite/index.cjs:7:31)
11:10:41.091 at Module._compile (internal/modules/cjs/loader.js:999:30)
11:10:41.095 at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)

pnpm run dev:h5:ssr 报错

一、错误信息如下:

/Users/xunwu/docod/test/uni-vue3-ts-template/node_modules/.pnpm/[email protected]/node_modules/vk-uview-ui/index.js:2
import mixin from './libs/mixin/mixin.js'
^^^^^^

SyntaxError: Cannot use import statement outside a module
at wrapSafe (internal/modules/cjs/loader.js:1001:16)
at Module._compile (internal/modules/cjs/loader.js:1049:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at ModuleWrap. (internal/modules/esm/translators.js:199:29)
at ModuleJob.run (internal/modules/esm/module_job.js:183:25)
at async Loader.import (internal/modules/esm/loader.js:178:24)
at async nodeImport (file:///Users/xunwu/docod/test/uni-vue3-ts-template/node_modules/.pnpm/[email protected]_ppdxls77r7tfsxvxidunrbldv4/node_modules/vite/dist/node/chunks/dep-51c4f80a.js:53132:21)
at async eval (/src/main.ts:9:31)
at async instantiateModule (file:///Users/xunwu/docod/test/uni-vue3-ts-template/node_modules/.pnpm/[email protected]_ppdxls77r7tfsxvxidunrbldv4/node_modules/vite/dist/node/chunks/dep-51c4f80a.js:53053:9)

二、如果package.js加入"type":"module",则报如下错误:

failed to load config from /Users/xunwu/docod/test/uni-vue3-ts-template/vite.config.ts

error when starting dev server:
TypeError: uni is not a function
at file:///Users/xunwu/docod/test/uni-vue3-ts-template/vite.config.ts.timestamp-1680072557068.mjs:9:5
at ModuleJob.run (internal/modules/esm/module_job.js:183:25)
at async Loader.import (internal/modules/esm/loader.js:178:24)
at async loadConfigFromBundledFile (file:///Users/xunwu/docod/test/uni-vue3-ts-template/node_modules/.pnpm/[email protected]_ppdxls77r7tfsxvxidunrbldv4/node_modules/vite/dist/node/chunks/dep-51c4f80a.js:62827:21)
at async loadConfigFromFile (file:///Users/xunwu/docod/test/uni-vue3-ts-template/node_modules/.pnpm/[email protected]_ppdxls77r7tfsxvxidunrbldv4/node_modules/vite/dist/node/chunks/dep-51c4f80a.js:62712:28)
at async resolveConfig (file:///Users/xunwu/docod/test/uni-vue3-ts-template/node_modules/.pnpm/[email protected]_ppdxls77r7tfsxvxidunrbldv4/node_modules/vite/dist/node/chunks/dep-51c4f80a.js:62336:28)
at async Module.createServer (file:///Users/xunwu/docod/test/uni-vue3-ts-template/node_modules/.pnpm/[email protected]_ppdxls77r7tfsxvxidunrbldv4/node_modules/vite/dist/node/chunks/dep-51c4f80a.js:61636:20)
at async createSSRServer (/Users/xunwu/docod/test/uni-vue3-ts-template/node_modules/.pnpm/@dcloudio[email protected][email protected][email protected]/node_modules/@dcloudio/vite-plugin-uni/dist/cli/server.js:42:18)
at async CAC.runDev (/Users/xunwu/docod/test/uni-vue3-ts-template/node_modules/.pnpm/@dcloudio[email protected][email protected][email protected]/node_modules/@dcloudio/vite-plugin-uni/dist/cli/action.js:22:28)
 ELIFECYCLE  Command failed with exit code 1.


 三、本地环境
 node: v14.19.3
 pnpm: 7.26.3

如何运行到真机

如图所示,直接引入项目安装完依赖运行后将会导致最新版HBuilderX-Alpha编译卡住
如果控制台运行pnpm dev:app 再导入HbuilderX则可以运行,而我需要引用原生插件,难以引入打基座。
环境是m1 mac os ventura 13.0.1
Screenshot 2022-11-23 at 10 00 57

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.