chore(cli): 由 HBuilderX 工程迁移为 uni-app Vue2 CLI 脚手架工程

- 业务源码统一迁入 src/,H5 模板移到 public/index.html
- 新增 @vue/cli 4.5 + @dcloudio 2.0.2-5020620260917001 全套依赖与 scripts
- 保留 vue.config.js 的 ROUTES 注入(uni-simple-router 运行时依赖)
- 新增 scripts/node-compat.cjs 兼容 Node 23+ 移除的 util.isRegExp 等 API
- README 补充构建/运行/回退说明
This commit is contained in:
liufumingren 2026-10-02 19:45:18 +08:00
parent 8318b3a688
commit 5ae92e0f63
609 changed files with 254 additions and 12 deletions

1
.npmrc Normal file
View File

@ -0,0 +1 @@
registry=https://registry.npmmirror.com

View File

@ -88,3 +88,35 @@
3. 再看接口返回结构是否包含 token
4. 最后看登录后是否成功调用 `user.info`
## 构建与运行(uni-app Vue2 CLI 工程)
> 本项目已从 HBuilderX 工程迁移为 `@vue/cli` 脚手架工程(2026-10-02):
> 业务源码全部位于 `src/`,H5 模板由 `public/index.html` 提供(即原根目录的 `template.h5.html`)。
### 命令
| 命令 | 作用 | 产物 |
| --- | --- | --- |
| `npm run dev:h5` | H5 开发服务器(默认 http://localhost:8080) | 内存编译 |
| `npm run build:h5` | H5 生产构建 | `dist/build/h5` |
| `npm run dev:app-plus` | App 资源监听编译 | `dist/dev/app-plus` |
| `npm run build:app-plus` | App 生产构建 | `dist/build/app-plus` |
| `npm run lint` | ESLint 自动修复 | - |
### App 端调试与打包
- CLI 不提供「运行到手机」:`build:app-plus` 只产出 App 资源,用 HBuilderX 导入 `dist/build/app-plus` 运行(或使用自定义基座、离线打包)。
- 正式云打包仍建议走 HBuilderX;`src/manifest.json` 中的 appid、模块、权限配置均保持原样。
### 注意事项
- **Node 版本**:当前在 Node 24 下构建,依赖两个脚本内开关——`--openssl-legacy-provider`(webpack 4 需要)与 `--require=./scripts/node-compat.cjs`(补回 Node 23+ 移除的 `util.isRegExp` 等历史 API)。若改用 Node 16/18,这两项会自动变成无害的空操作。
- **`ROUTES` 常量**:由根目录 `vue.config.js`(`uni-read-pages` + DefinePlugin)注入,`uni-simple-router` 内部依赖它;缺失会在运行时抛 `ReferenceError: ROUTES is not defined`,请勿删除该配置。
- **@dcloudio 版本必须整体一致**:当前锁定 `2.0.2-5020620260917001`(Vue2 线),升级时需全量同版本替换。
- **依赖镜像**:`.npmrc` 指向 `registry.npmmirror.com`。
- `src/pages/componentsA|B|C` 是 uView 官方示例页(含 67 个 `.nvue` 文件),未被 `pages.json` 注册、不参与编译,可按需删除。
### 回退方式
原 HBuilderX 工程完整备份在 `d:\WMS_PDA_bak_20261002-1936`(含 `node_modules`、`.hbuilderx`、`template.h5.html`、`vue.config.js`、`package.json`、`package-lock.json`)。需要回退时,把备份内容覆盖回项目根目录即可。

81
babel.config.js Normal file
View File

@ -0,0 +1,81 @@
const webpack = require('webpack')
const plugins = []
if (process.env.UNI_OPT_TREESHAKINGNG) {
plugins.push(require('@dcloudio/vue-cli-plugin-uni-optimize/packages/babel-plugin-uni-api/index.js'))
}
if (
(
process.env.UNI_PLATFORM === 'app-plus' &&
process.env.UNI_USING_V8
) ||
(
process.env.UNI_PLATFORM === 'h5' &&
process.env.UNI_H5_BROWSER === 'builtin'
)
) {
const path = require('path')
const isWin = /^win/.test(process.platform)
const normalizePath = path => (isWin ? path.replace(/\\/g, '/') : path)
const input = normalizePath(process.env.UNI_INPUT_DIR)
try {
plugins.push([
require('@dcloudio/vue-cli-plugin-hbuilderx/packages/babel-plugin-console'),
{
file (file) {
file = normalizePath(file)
if (file.indexOf(input) === 0) {
return path.relative(input, file)
}
return false
}
}
])
} catch (e) { }
}
process.UNI_LIBRARIES = process.UNI_LIBRARIES || ['@dcloudio/uni-ui']
process.UNI_LIBRARIES.forEach(libraryName => {
plugins.push([
'import',
{
'libraryName': libraryName,
'customName': (name) => {
return `${libraryName}/lib/${name}/${name}`
}
}
])
})
if (process.env.UNI_PLATFORM !== 'h5') {
plugins.push('@babel/plugin-transform-runtime')
}
const config = {
presets: [
[
'@vue/app',
{
modules: webpack.version[0] > 4 ? 'auto' : 'commonjs',
useBuiltIns: process.env.UNI_PLATFORM === 'h5' ? 'usage' : 'entry'
}
]
],
plugins
}
const UNI_H5_TEST = '**/@dcloudio/uni-h5/dist/index.umd.min.js'
if (process.env.NODE_ENV === 'production') {
config.overrides = [{
test: UNI_H5_TEST,
compact: true,
}]
} else {
config.ignore = [UNI_H5_TEST]
}
module.exports = config

View File

@ -1,17 +1,61 @@
{
"id": "uview-ui",
"name": "wms-pda",
"version": "1.0.8",
"private": true,
"description": "天豹云仓 WMS_PDA(uni-app Vue2 + @vue/cli 4.5)",
"scripts": {
"serve": "npm run dev:h5",
"build": "npm run build:h5",
"dev:h5": "cross-env NODE_ENV=development UNI_PLATFORM=h5 NODE_OPTIONS=\"--openssl-legacy-provider --require=./scripts/node-compat.cjs\" vue-cli-service uni-serve",
"dev:app-plus": "cross-env NODE_ENV=development UNI_PLATFORM=app-plus NODE_OPTIONS=\"--openssl-legacy-provider --require=./scripts/node-compat.cjs\" vue-cli-service uni-build --watch",
"build:h5": "cross-env NODE_ENV=production UNI_PLATFORM=h5 NODE_OPTIONS=\"--openssl-legacy-provider --require=./scripts/node-compat.cjs\" vue-cli-service uni-build",
"build:app-plus": "cross-env NODE_ENV=production UNI_PLATFORM=app-plus NODE_OPTIONS=\"--openssl-legacy-provider --require=./scripts/node-compat.cjs\" vue-cli-service uni-build",
"lint": "eslint . --fix",
"test": "eslint . --fix"
},
"dependencies": {
"@dcloudio/uni-app": "2.0.2-5020620260917001",
"@dcloudio/uni-app-plus": "2.0.2-5020620260917001",
"@dcloudio/uni-h5": "2.0.2-5020620260917001",
"@dcloudio/uni-i18n": "2.0.2-5020620260917001",
"@dcloudio/uni-mp-vue": "2.0.2-5020620260917001",
"@dcloudio/uni-mp-weixin": "2.0.2-5020620260917001",
"@dcloudio/uni-stat": "2.0.2-5020620260917001",
"core-js": "^3.8.3",
"html2canvas": "^1.4.1",
"pinyin-pro": "^3.28.0",
"qrcode": "^1.5.4",
"regenerator-runtime": "^0.12.1",
"uni-read-pages": "^1.0.5",
"uqrcodejs": "^4.0.7"
"uqrcodejs": "^4.0.7",
"vue": ">= 2.6.14 < 2.7",
"vuex": "^3.6.2"
},
"devDependencies": {
"@dcloudio/uni-cli-i18n": "2.0.2-5020620260917001",
"@dcloudio/uni-cli-shared": "2.0.2-5020620260917001",
"@dcloudio/uni-migration": "2.0.2-5020620260917001",
"@dcloudio/uni-template-compiler": "2.0.2-5020620260917001",
"@dcloudio/vue-cli-plugin-hbuilderx": "2.0.2-5020620260917001",
"@dcloudio/vue-cli-plugin-uni": "2.0.2-5020620260917001",
"@dcloudio/vue-cli-plugin-uni-optimize": "2.0.2-5020620260917001",
"@dcloudio/webpack-uni-mp-loader": "2.0.2-5020620260917001",
"@dcloudio/webpack-uni-pages-loader": "2.0.2-5020620260917001",
"@vue/cli-plugin-babel": "~4.5.0",
"@vue/cli-service": "~4.5.0",
"babel-plugin-import": "^1.11.0",
"copy-webpack-plugin": "^5.1.2",
"cross-env": "^7.0.2",
"eslint": "^8.2.0",
"eslint-config-airbnb": "^19.0.0"
}
"eslint-config-airbnb": "^19.0.0",
"postcss": "^7.0.39",
"postcss-comment": "^2.0.0",
"sass": "~1.49.8",
"sass-loader": "^8.0.2",
"vue-template-compiler": ">= 2.6.14 < 2.7"
},
"browserslist": [
"Android >= 4.4",
"iOS >= 9"
]
}

27
postcss.config.js Normal file
View File

@ -0,0 +1,27 @@
const path = require('path')
const webpack = require('webpack')
const config = {
parser: require('postcss-comment'),
plugins: [
require('postcss-import')({
resolve (id, basedir, importOptions) {
if (id.startsWith('~@/')) {
return path.resolve(process.env.UNI_INPUT_DIR, id.substr(3))
} else if (id.startsWith('@/')) {
return path.resolve(process.env.UNI_INPUT_DIR, id.substr(2))
} else if (id.startsWith('/') && !id.startsWith('//')) {
return path.resolve(process.env.UNI_INPUT_DIR, id.substr(1))
}
return id
}
}),
require('autoprefixer')({
remove: process.env.UNI_PLATFORM !== 'h5'
}),
require('@dcloudio/vue-cli-plugin-uni/packages/postcss')
]
}
if (webpack.version[0] > 4) {
delete config.parser
}
module.exports = config

View File

@ -28,9 +28,6 @@
<link rel="stylesheet" href="<%= BASE_URL %>static/index.css" />
</head>
<body>
<!-- 该文件为 H5 平台的模板 HTML,并非应用入口。 -->
<!-- 请勿在此文件编写页面代码或直接运行此文件。 -->
<!-- 详见文档:https://uniapp.dcloud.io/collocation/manifest?id=h5-template -->
<noscript>
<strong>本站点必须要开启JavaScript才能运行</strong>
</noscript>

52
scripts/node-compat.cjs Normal file
View File

@ -0,0 +1,52 @@
/**
* Node 兼容 shim(uni-app Vue2 工具链专用)
*
* 背景:Node 23+ 移除了历史遗留的 `util.isArray` / `util.isRegExp` 等 API,
* 而 uni-app Vue2 编译链依赖的 postcss-urlrewrite 等老包仍在调用它们,
* 在 Node 22+ 上执行 app-plus 构建会抛 `util.isRegExp is not a function`。
*
* 用法:通过 NODE_OPTIONS=--require=./scripts/node-compat.cjs 注入(见 package.json scripts)。
* 在 Node 16/18 下运行时所有 API 均存在,本文件自动变成空操作,无副作用。
*/
'use strict'
const util = require('util')
const toString = Object.prototype.toString
const shims = {
isArray: Array.isArray,
isBoolean: (v) => typeof v === 'boolean',
isBuffer: (v) => Buffer.isBuffer(v),
isDate: (v) => v instanceof Date,
isError: (v) => v instanceof Error || toString.call(v) === '[object Error]',
isFunction: (v) => typeof v === 'function',
isNull: (v) => v === null,
isNullOrUndefined: (v) => v === null || v === undefined,
isNumber: (v) => typeof v === 'number',
isObject: (v) => v !== null && typeof v === 'object',
isPrimitive: (v) => v === null || (typeof v !== 'object' && typeof v !== 'function'),
isRegExp: (v) => v instanceof RegExp,
isString: (v) => typeof v === 'string',
isSymbol: (v) => typeof v === 'symbol',
isUndefined: (v) => v === undefined
}
Object.keys(shims).forEach((name) => {
if (typeof util[name] !== 'function') {
util[name] = shims[name]
}
})
if (typeof util._extend !== 'function') {
util._extend = function _extend (target, source) {
if (source) {
for (const key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key]
}
}
}
return target
}
}

View File

View File

@ -134,7 +134,6 @@
"appid" : ""
},
"h5" : {
"template" : "template.h5.html",
"router" : {
"mode" : "history",
"base" : ""

Some files were not shown because too many files have changed in this diff Show More