niucloud/uni-app/vite.config.addon.ts
niuzhiyun 5c0437cf53 v2.1.0-beta
1. 云编译任务系统的全面升级。 整个云编译服务器使用高性能开发语言GO全面重建整个的任务,排队体系。框架的用户,全面引入了任务管理系统设计架构。把云编译,在线升级,插件打包,构建发布版本,小程序一键上传同步等流程,高度抽象为任务系统。整个任务的执行过程会详细记录下来,支持每个过程的原始执行情况回溯。每个步骤,执行错误,加入重试与取消机制。对于网络拥堵,网络暂时断开造成的上传下载过程中不可预测的中断开始支持断点续传重续。同时,云编译支持前端驱动,与后端Redis队列驱动两种模式。前端驱动模式为轻量模式,需要页面的持续保持任务的进行。Redis队列驱动模式,支持任务后台运行,在任务后台运行的同时,同步进行业务系统的正常使用
2. 多端口,自定义扩展端口的真正支持。历史版本中,在addon.info中,已经设计有自定义端口功能,但是在整个的云编译服务器,没有真正支持自定义端口的编译与部署。在本次版本中,服务器端,以及框架已经全部支持自定义端口使能。addon.info 文件中定义的端口,会在编译端口自动枚举展示。云编译过程,会按照设定的命令自动执行,并完成部署。同时,云编译支持框架独立编译,插件组合编译等,方便开发者使用。
3. 环境检测与数据库修复,在本版本中全面引入。数据库修复,支持全量比对,表比对,插件比对,字符集编码比对,数据库修复功能,可以按照插件比对出缺失字段,并通过一键修复按钮完成数据库的修复。对于第三方插件中数据库表与框架自身不同的情况,系统会自动修正并正确执行SQL脚本。
4. 补丁管理也在本版本中实现,对于小问题,及时问题的处理,会发布小版本补丁。用户可以及时下载补丁,实时完成系统缺漏的修复。
5. 菜单系统,加入了导入菜单,导出菜单功能。niucloud开发团队全力为开发者考虑,本版本导入导出菜单可以按照插件,或者整个框架把菜单结构导出为json格式。
6. 构建版本在本次升级新加入。构建版本可以把云编译及版本构建的版本发布过程保留下来。
7. 插件校验和框架系统校验。在本版本中全面引入。支持对插件和框架进行全面校验比对。支持一键修复二开或者异常代码修复。
8. 存储设置在本版本全面优化,支持新增多种不同存储厂商的配置,并支持在不同配置中切换使用。
9. 运营面板在本次升级中植入。运营面板相当于为应用和插件加入了admin端的管理入口。本次版本开放此功能,为开发者开发admin端口功能提供了基础。我们官方在本次版本中同步发布官方客服插件,在admin端加入了平台客服的演示案例,供大家感受学习。
10. 全面优化了admin端的界面风格,加入了新的站点端默认风格。框架内置‌Vben Admin 前端框架。其实niucloud优秀的架构设计,运行速度并不慢,加入‌Vben Admin后,页面的切换效果会让用户感受到更加的丝滑与现代。
11. 前端顶部轮播组件,加入了返回首页按钮。 装修后,完美支持美团,饿了么那种模块与主模块的完美切换。
12. 小程序编译结构进行了优化,整个运行的速度更加快速。
2026-09-30 18:02:42 +08:00

141 lines
6.2 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { fileURLToPath, URL } from 'node:url'
import { createRequire } from 'node:module'
import { defineConfig } from 'vite'
import uni from '@dcloudio/vite-plugin-uni'
import WindiCSS from 'vite-plugin-windicss'
const require = createRequire(import.meta.url)
const { isSharedExternal, isWapLocaleExternal, isDiyCoreExternal } = require('./scripts/shared-external.cjs')
const { createForceSharedExternalPlugin, createForceLocaleExternalPostPlugin, sharedOutputPaths } = require('./scripts/vite-plugin-force-shared-external.cjs')
const { createDiyGroupFixPlugin } = require('./scripts/vite-plugin-diy-group-fix.cjs')
const { createDiyGroupSplitPlugin } = require('./scripts/vite-plugin-diy-group-split.cjs')
const { toViteDefine, getUniFeatureDefines } = require('./scripts/uni-feature-defines.cjs')
const uniH5Shim = fileURLToPath(new URL('./scripts/uni-h5-global-shim.ts', import.meta.url))
const addonKey = process.env.ADDON_KEY || ''
if (!addonKey) {
throw new Error('ADDON_KEY is required for addon build')
}
const entry = fileURLToPath(new URL(`./.build/addons/${addonKey}/entry.ts`, import.meta.url))
/** Rollup 插件:在构建时替换插件中的 navigateTo 实现,委托给 globalThis.uni */
function createNavDelegatePlugin() {
return {
name: 'nav-delegate',
generateBundle(_opts: any, bundle: any) {
for (const key of Object.keys(bundle)) {
const chunk = bundle[key]
if (chunk.type !== 'chunk') continue
if (!chunk.code || !chunk.code.includes('defineAsyncApi')) continue
if (!chunk.code.includes('const navigateTo')) continue
let code = chunk.code
// 精确替换 const navigateTo/redirectTo/reLaunch 定义(到 \nconst 或 \nfunction 为止)
const patchNav = (name: string) => {
const re = new RegExp(`const ${name}\\s*=\\s*[\\s\\S]*?;(?=\\s*(const |function |var |let |class |async |export |import |$))`, 'g')
const replacement = `const ${name}=function(a){var u=globalThis.uni;return u&&u.${name}?u.${name}(a):Promise.reject({errMsg:"${name}:fail"})};`
code = code.replace(re, replacement)
}
patchNav('navigateTo')
patchNav('redirectTo')
patchNav('reLaunch')
if (code !== chunk.code) {
chunk.code = code
console.log('[nav-delegate] patched ' + key)
}
}
}
}
}
/** 单插件 H5 lib 构建 */
export default defineConfig({
publicDir: false,
define: {
'process.env.NODE_ENV': JSON.stringify('production'),
__VUE_OPTIONS_API__: true,
__WAP_SPLIT_BUILD__: JSON.stringify(true),
...toViteDefine(getUniFeatureDefines())
},
plugins: [
createDiyGroupSplitPlugin(),
createForceSharedExternalPlugin(),
createForceLocaleExternalPostPlugin(),
uni(),
createDiyGroupFixPlugin(),
createNavDelegatePlugin(),
// 把真实入口文件名写入 entry.json:大插件的懒加载 chunk(components/xxx/index.vue)
// basename 也叫 index,产物中会同时存在多个 index-[hash].js,仅凭文件名/mtime 无法区分入口;
// resolveAddonEntry 优先读取该文件精确解析 manifest.entry
{
name: 'emit-addon-manifest',
generateBundle(_opts: any, bundle: any) {
for (const name of Object.keys(bundle)) {
const b = bundle[name]
if (b && b.type === 'chunk' && b.isEntry) {
// 构建期直接写出插件 manifest.json(含内容哈希入口),sync/运行时都以其为准,无需扫描目录
const manifest = {
key: addonKey,
version: '1.0.0',
sharedVersion: 'wap-core-1.0.0',
entry: b.fileName,
localeBase: './locale/'
}
this.emitFile({ type: 'asset', fileName: 'manifest.json', source: JSON.stringify(manifest, null, 2) + '\n' })
break
}
}
}
},
WindiCSS({
scan: {
dirs: [
`src/addon/${addonKey}`,
'src/components'
],
fileExtensions: ['vue', 'js', 'ts']
}
})
],
resolve: {
alias: [
{
find: /^@\/utils\/diy-component-registry$/,
replacement: fileURLToPath(new URL('./src/utils/diy-component-registry.split.ts', import.meta.url))
},
{
find: /^@\/utils\/diy-component-loader$/,
replacement: fileURLToPath(new URL('./src/utils/diy-component-loader.split.ts', import.meta.url))
},
{ find: '@/utils/addon-loader', replacement: fileURLToPath(new URL('./src/utils/addon-loader.split.ts', import.meta.url)) },
{ find: '@', replacement: fileURLToPath(new URL('./src', import.meta.url)) },
{ find: '@dcloudio/uni-h5/dist/uni-h5.es.js', replacement: uniH5Shim }
]
},
build: {
outDir: `dist/.addons/${addonKey}`,
emptyOutDir: true,
lib: {
entry,
formats: ['es'],
// 入口文件名由 rollupOptions.output.entryFileNames 决定(带 contenthash)
fileName: () => 'index'
},
rollupOptions: {
external: (id) => isDiyCoreExternal(id) || isWapLocaleExternal(id) || isSharedExternal(id),
output: {
inlineDynamicImports: false,
// 入口按内容哈希命名:index-[hash].js(Rollup 的 [hash] 即内容哈希,等价于 Webpack 的 [contenthash])。
// 浏览器按文件名缓存,重新编译后文件名变化 → 旧缓存自然失效,无需强刷
chunkFileNames: '[name]-[hash].js',
entryFileNames: 'index-[hash].js',
paths(id) {
return sharedOutputPaths(id)
}
}
}
}
})