diff --git a/README.md b/README.md index 5da1b37ba94955a2bf33d4f43452747aea6d8fa0..9fc79cb4139119c71bdcf0607204b95326249398 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,14 @@ # uni-app +

+ 简体中文 | English +

+ `uni-app` 是一个使用 `Vue.js` 开发小程序、H5、App的统一前端框架。官网地址:[https://uniapp.dcloud.io](https://uniapp.dcloud.io) 开发者使用 `Vue` 语法编写代码,`uni-app` 框架将其编译到 小程序(微信/支付宝/百度/字节跳动/QQ/快手/钉钉/小红书)、App(iOS/Android)、H5等多个平台,保证其正确运行并达到优秀体验。 + # uni-app的特点 - 开发者和案例更多:HBuilder装机量800万台,开发者社区月活百万,70多个QQ微信群承载10万人。案例众多,uni统计月活超10亿([详见](https://uniapp.dcloud.io/case)) @@ -17,7 +22,9 @@ 开发一次,编译到11个平台。依次扫描11个二维码,亲自体验最全面的跨平台效果! - +
+ +
*注: 某些平台不能提交简单demo,补充了一些其他功能。* diff --git a/README_en-US.md b/README_en-US.md new file mode 100644 index 0000000000000000000000000000000000000000..7d70e65978213ade593ea01f6d42700b681dd763 --- /dev/null +++ b/README_en-US.md @@ -0,0 +1,86 @@ +# uni-app + +

+ 简体中文 | English +

+ +`uni-app` is a unified front-end framework that uses `Vue.js` to develop applet, H5, and App. Official website address: [https://uniapp.dcloud.io](https://uniapp.dcloud.io) + +Developers use `Vue` syntax to write code, and `uni-app` framework compiles it into small programs (WeChat/Alipay/Baidu/ByteDance/QQ/Kuishou/Dingding/Xiaohongshu), App (iOS/Android) ), H5 and other platforms to ensure its correct operation and achieve an excellent experience. + +# Features of uni-app + +- More developers and cases: HBuilder has installed 8 million units, the developer community has one million monthly active users, and more than 70 QQ and WeChat groups carry 100,000 people. There are many cases, and the uni statistics exceed 1 billion monthly active users ([see details](https://uniapp.dcloud.io/case)) +- Higher performance (see [Review](https://juejin.im/post/5ca1736af265da30ae314248)) +- Richer surrounding ecology, [Plugin Market](https://ext.dcloud.net.cn/) thousands of plugins +- Provide a better development experience and higher engineering efficiency than the native development of small programs +- The smoothness across the ends is more complete, and the characteristics of each end are more flexible, which can truly achieve multi-end coverage of a set of codes, without the need for multi-end maintenance and upgrades at each end +- Authoritative recognition: Alipay's official tool has built-in uni-app ([see details](https://docs.alipay.com/mini/ide/0.70-stable)), Tencent Classroom's official self-made uni-app training video ([ For details, see](https://ask.dcloud.net.cn/article/35640)) + +## Scan code experience + +Develop once, compile to 3 platforms. Scan 3 QR codes in sequence to experience the most comprehensive cross-platform effect for yourself! + +
+ +
+ +## quick start + +`uni-app` supports two ways to quickly create projects through the `vue-cli` command line and the `HBuilderX` visual interface: + +- [vue-cli command line mode](https://uniapp.dcloud.io/quickstart?id=_2-%E9%80%9A%E8%BF%87vue-cli%E5%91%BD%E4%BB%A4%E8%A1%8C): not limited to IDE, suitable for developers familiar with node, extended reading: [Developing uni-app in vscode](https://ask.dcloud.net.cn/article/36286 ), [Developing uni-app in WebStorm](https://ask.dcloud.net.cn/article/36307) +- [HBuilderX visual interface](https://uniapp.dcloud.io/quickstart?id=_1-%E9%80%9A%E8%BF%87-hbuilderx-%E5%8F%AF%E8%A7%86%E5%8C%96%E7%95%8C%E9%9D%A2): dedicated IDE, built-in related environment, out-of-the-box, and higher development efficiency. + +## Project cases + +Case show: [uniapp.dcloud.io/case](https://uniapp.dcloud.io/case) + +Welcome to submit your application, [uni-app case collection](https://github.com/dcloudio/uni-app/issues/6) + +## Demand Wall + +The function points supported by the `uni-app` plan will be displayed on the demand wall, and the voting opinions of developers will be collected. [Go to Vote](https://dev.dcloud.net.cn/wish/). + +## Changelog + +`uni-app` has always maintained high-frequency update iterations. For details, see [Official version update log](https://uniapp.dcloud.net.cn/release), [Alpha version update log](https://uniapp. dcloud.net.cn/release-note-alpha). + +## Forum + +Since `DCloud` has more than 70 QQ and WeChat groups, the official has been unable to maintain more communication groups. Please go to the official forum to communicate: [https://ask.dcloud.net.cn/explore/](https://ask.dcloud.net.cn/explore/). Forums provide more professional tools and services than issues. + +## Plugin Market + +`uni-app` has a rich plugin ecosystem. Many developers have submitted thousands of components, sdk, and project templates. For details, see: [https://ext.dcloud.net.cn/](https://ext.dcloud.net.cn/) + +In addition to many third-party ui libraries, the official also provides uni-ui, which has stronger advantages in performance and cross-end compatibility. For details, see: [https://ext.dcloud.net.cn/plugin?id=55](https://ext.dcloud.net.cn/plugin?id=55) + +## How to migrate existing projects to uni-app system + +- WeChat applet conversion uni-app guide and converter: [https://ask.dcloud.net.cn/article/35786](https://ask.dcloud.net.cn/article/35786) +- Vue h5 project conversion uni-app guide: [https://ask.dcloud.net.cn/article/36174](https://ask.dcloud.net.cn/article/36174) +- mpvue project (component) migration guide, example and resource summary: [https://ask.dcloud.net.cn/article/34945](https://ask.dcloud.net.cn/article/34945) +- wepy to uni-app converter: [https://github.com/zhangdaren/wepy-to-uniapp](https://github.com/zhangdaren/wepy-to-uniapp) + +## Frequently Asked Questions + +- Q: Different terminals have different needs and features, and login and payment are also different. How to unify? +- A: The difference part uses conditional compilation. uni-app provides flexible and powerful [conditional compilation](https://uniapp.dcloud.io/platform). Can perfectly handle the multiplexed part and the difference part. A real set of project source code. When the business is upgraded, multi-terminal maintenance is no longer required. If there is multi-end maintenance, it is often delayed because the traffic on some ends is not large, so that those users cannot enjoy the latest services. In addition, the login payment in the client part has been unified into the same api by uni-app. + + +- Q: Is multi-terminal a compromise and will it cause performance degradation? +- A: good question. It's really hard to be multi-terminal without compromising performance, but uni-app does it. On the h5 side, its performance and package size are consistent with those developed directly using vue.js; on the applet side, its performance is better than most development frameworks. It is better for the user to manually write setdata, just as it is more efficient to use vue.js to update the interface than to manually write js to modify the dom; in App, uni-app supports dual engines for webview rendering and native rendering. When native rendering is enabled, css writing is limited, However, the performance is very close to the effect of native development. In the current mobile phone environment, applications with less than ten million daily activities will not encounter any pressure when using uni-app in the App. Of course, it is also possible to change some pages to uni-app in the native app that has already been done; in addition, we will complete a lot of cross-end processing at the compile time, which will reduce the efficiency impact on the runtime. + + +- Q: Do you not need uni-app if you don't do multi-end? +- A: No. A large number of developers use uni-app as only one end, see [Case](https://uniapp.dcloud.io/case) for details. For developers, with an excellent tool in hand, there is nothing to worry about. + +- Q: Will uni-app change the open source protocol and switch to charging in the future? +- A: The official promise will never change the open source agreement. Regardless of HBuilderX, uni-app, or App, it is always free for Chinese people. + +## more info + +- Evaluation: [Cross-end Development Framework Deep Heng Evaluation 2020 Edition](https://juejin.im/post/5e8e8d5a6fb9a03c6d3d9f42) +- Evaluation: [In-depth testing for a week, mainstream multi-terminal frameworks compete](https://mp.weixin.qq.com/s/jIDEHfuMnED6HTfNgjsW4w) +- [Comparison of uni-app on the App side with flutter and react native](https://ask.dcloud.net.cn/article/36083) diff --git a/package.json b/package.json index 4e75fe6b4b2fb78a121eac21d1c758c469605887..6e098f2b2cc109f15fcb579fe7f9a3b8b9a9e7fd 100644 --- a/package.json +++ b/package.json @@ -63,6 +63,7 @@ "copy": "^0.3.2", "cross-env": "^7.0.2", "del": "^5.1.0", + "escape-string-regexp": "4", "eslint": "^6.8.0", "eslint-config-standard": "^14.1.0", "eslint-loader": "^3.0.3", @@ -71,6 +72,7 @@ "eslint-plugin-promise": "^4.2.1", "eslint-plugin-standard": "^4.0.1", "eslint-plugin-vue": "^6.2.2", + "glob-escape": "^0.0.2", "i18n": "^0.13.3", "jest": "^25.1.0", "jsdom": "^16.2.1", @@ -153,4 +155,4 @@ "main": "index.js", "description": "", "author": "" -} \ No newline at end of file +} diff --git a/packages/uni-cli-i18n/locales/en.json b/packages/uni-cli-i18n/locales/en.json index be37499fc1bac44ca50ef4539a0257de2a834d93..512476777c27880d9e0fbb298d3d429b6c442a81 100644 --- a/packages/uni-cli-i18n/locales/en.json +++ b/packages/uni-cli-i18n/locales/en.json @@ -33,7 +33,7 @@ "templateCompiler.noH5KeyNoSupportExpression": "Non-h5 platforms: key does not support expression {{0}}, for details, please refer to: {{1}}", "templateCompiler.notCurrentlySupportScopedSlot": "Not currently supported scoped slot {{0}}", "templateCompiler.idAttribNotAllowInCustomComponentProps": "id is reserved as a property name and is not allowed to be defined as props in custom component {{0}}", - "templateCompiler.notSupportDynamicSlotName": "{{0}} Does not support dynamic slot names", + "templateCompiler.notSupportDynamicSlotName": "{{0}} Does not support dynamic slot names, please use scopedSlotsCompiler: augmented", "templateCompiler.forNestedIndexNameNoArrowRepeat": "{{0}} When v-for is nested, the index name {{1}} is not allowed to be repeated", "templateCompiler.noSupportSyntax": "Does not support {{0}} syntax", "pluginHbuilderx.plaseHXCompileAppPlatform": "Please use HBuilderX to compile and run to the app-plus platform", diff --git a/packages/uni-cli-i18n/locales/zh_CN.json b/packages/uni-cli-i18n/locales/zh_CN.json index c48eb8b62b563ef14075e66adc40656af5050389..a86b19ca3765e01dee1c6d83b2b6b8b6d6001b8d 100644 --- a/packages/uni-cli-i18n/locales/zh_CN.json +++ b/packages/uni-cli-i18n/locales/zh_CN.json @@ -33,7 +33,7 @@ "templateCompiler.noH5KeyNoSupportExpression": "非 h5 平台 :key 不支持表达式 {{0}},详情参考: {{1}}", "templateCompiler.notCurrentlySupportScopedSlot": "暂不支持 scoped slot {{0}}", "templateCompiler.idAttribNotAllowInCustomComponentProps": "id 作为属性保留名,不允许在自定义组件 {{0}} 中定义为 props", - "templateCompiler.notSupportDynamicSlotName": "{{0}} 不支持动态插槽名", + "templateCompiler.notSupportDynamicSlotName": "{{0}} 不支持动态插槽名,请设置 scopedSlotsCompiler 为 augmented", "templateCompiler.forNestedIndexNameNoArrowRepeat": "{{0}} v-for 嵌套时,索引名称 {{1}} 不允许重复", "templateCompiler.noSupportSyntax": "不支持 {{0}} 语法", "pluginHbuilderx.plaseHXCompileAppPlatform": "请使用 HBuilderX 编译运行至 app-plus 平台", diff --git a/packages/uni-cli-shared/__tests__/util.spec.js b/packages/uni-cli-shared/__tests__/util.spec.js new file mode 100644 index 0000000000000000000000000000000000000000..0e4218c37ff3e3b08813d57e73191338b7c0b1bf --- /dev/null +++ b/packages/uni-cli-shared/__tests__/util.spec.js @@ -0,0 +1,35 @@ +const { + pathToRegexp, + pathToGlob +} = require('../lib/util') + +describe('pathToRegexp', () => { + function expectRegexp (pathString, options, source, flags = 'i') { + const exp = pathToRegexp(pathString, options) + expect(exp.source).toBe(source) + expect(exp.flags).toBe(flags) + } + it('path', () => { + expectRegexp('/test', {}, '\\/test') + expectRegexp('/test(1', {}, '\\/test\\(1') + }) + it('path with options', () => { + expectRegexp('/test', { start: true }, '^\\/test') + expectRegexp('/test', { end: true }, '\\/test$') + expectRegexp('/test', { start: true, end: true }, '^\\/test$') + expectRegexp('/test', { global: true }, '\\/test', 'gi') + }) +}) + +describe('pathToGlob', () => { + it('path in unix', () => { + expect(pathToGlob('/test', '**/*.js')).toBe('/test/**/*.js') + expect(pathToGlob('/test(1', '**/*.js')).toBe('/test[(]1/**/*.js') + expect(pathToGlob('/test(1', '**/*.js', { escape: true })).toBe('/test\\(1/**/*.js') + }) + it('path in windows', () => { + expect(pathToGlob('C:\\\\test\\test', '**/*.js', { windows: true })).toBe('C:/test/test/**/*.js') + expect(pathToGlob('C:\\\\test\\test(1', '**/*.js', { windows: true })).toBe('C:/test/test[(]1/**/*.js') + expect(pathToGlob('C:\\\\test\\test(1', '**/*.js', { windows: true, escape: true })).toBe('C:/test/test[(]1/**/*.js') + }) +}) diff --git a/packages/uni-cli-shared/lib/preprocess.js b/packages/uni-cli-shared/lib/preprocess.js index b495e812b19c4ef6754eaaec32b080cae113125a..46faf009a8db104ab62c8b68457f36db7956fce3 100644 --- a/packages/uni-cli-shared/lib/preprocess.js +++ b/packages/uni-cli-shared/lib/preprocess.js @@ -51,7 +51,8 @@ module.exports = function initPreprocess (name, platforms, userDefines = {}) { } if (name.startsWith('app-')) { - vueContext.APP = true + vueContext.APP = true + nvueContext.APP = true } if (name === 'quickapp-webview') { diff --git a/packages/uni-cli-shared/lib/source-map.js b/packages/uni-cli-shared/lib/source-map.js index 20cc191e5c3265d1a53f0518bac2e855b3dc7e60..84e9ec4d23e2f3fcebe3685c6acac4d7b8a4aeee 100644 --- a/packages/uni-cli-shared/lib/source-map.js +++ b/packages/uni-cli-shared/lib/source-map.js @@ -4,16 +4,10 @@ const webpack = require('webpack') const { normalizePath, + pathToRegexp, isInHBuilderX } = require('@dcloudio/uni-cli-shared/lib/util') -const isWin = /^win/.test(process.platform) - -function genTranspileDepRegex (depPath) { - return new RegExp(isWin - ? depPath.replace(/\\/g, '\\\\') // double escape for windows style path - : depPath) -} let sourceRoot = false function getSourceRoot () { @@ -60,7 +54,7 @@ module.exports = { }, createEvalSourceMapDevToolPlugin () { return new webpack.EvalSourceMapDevToolPlugin({ - test: genTranspileDepRegex(process.env.UNI_INPUT_DIR), + test: pathToRegexp(process.env.UNI_INPUT_DIR, { start: true }), exclude, moduleFilenameTemplate }) diff --git a/packages/uni-cli-shared/lib/util.js b/packages/uni-cli-shared/lib/util.js index e0190815fba4fc0174d8775b28884b78e7880357..19dc3e8041589bed505dcee966136e36c07a9407 100644 --- a/packages/uni-cli-shared/lib/util.js +++ b/packages/uni-cli-shared/lib/util.js @@ -2,6 +2,8 @@ const path = require('path') const fs = require('fs') const hash = require('hash-sum') const crypto = require('crypto') +const escapeStringRegexp = require('escape-string-regexp') +const escapeGlob = require('glob-escape') const isWin = /^win/.test(process.platform) @@ -121,6 +123,34 @@ function normalizeNodeModules (str) { const _hasOwnProperty = Object.prototype.hasOwnProperty +/** + * pathToRegexp + * @param {string} pathString + * @param {{start:?boolean,end:?boolean,global:?boolean}?} options + * @returns {RegExp} + */ +function pathToRegexp (pathString, options = {}) { + return new RegExp((options.start ? '^' : '') + escapeStringRegexp(pathString) + (options.end ? '$' : ''), 'i' + (options.global ? 'g' : '')) +} + +/** + * pathToGlob + * @param {string} pathString + * @param {string} glob + * @param {{windows:?boolean,escape:?boolean}?} options + * @returns {string} + */ +function pathToGlob (pathString, glob, options = {}) { + const isWindows = 'windows' in options ? options.windows : /^win/.test(process.platform) + const useEscape = options.escape + const str = isWindows ? pathString.replace(/\\/g, '/') : pathString + let safeStr = escapeGlob(str) + if (isWindows || !useEscape) { + safeStr = safeStr.replace(/\\(.)/g, '[$1]') + } + return path.posix.join(safeStr, glob) +} + module.exports = { isInHBuilderX, isInHBuilderXAlpha, @@ -149,6 +179,8 @@ module.exports = { hyphenate, normalizePath, convertStaticStyle, + pathToRegexp, + pathToGlob, getComponentName: cached((str) => { if (str.indexOf('wx-') === 0) { return str.replace('wx-', 'weixin-') diff --git a/packages/uni-cli-shared/package.json b/packages/uni-cli-shared/package.json index a716e10b73784393dd8115683db30d196fc8ff41..63d5c8c88ee87f34a0123c18abef8fc35302b691 100644 --- a/packages/uni-cli-shared/package.json +++ b/packages/uni-cli-shared/package.json @@ -19,6 +19,8 @@ "author": "fxy060608", "license": "Apache-2.0", "dependencies": { + "escape-string-regexp": "^4.0.0", + "glob-escape": "^0.0.2", "hash-sum": "^1.0.2", "postcss-urlrewrite": "^0.2.2", "strip-json-comments": "^2.0.1" diff --git a/packages/uni-template-compiler/__tests__/compiler-extra.spec.js b/packages/uni-template-compiler/__tests__/compiler-extra.spec.js index 4dcb81d258f4e7bd46794c2f57a59f7669151013..132c8fd062651d690d0749f431b6cb147e606e49 100644 --- a/packages/uni-template-compiler/__tests__/compiler-extra.spec.js +++ b/packages/uni-template-compiler/__tests__/compiler-extra.spec.js @@ -545,6 +545,11 @@ describe('mp:compiler-extra', () => { '4', '4' ) + assertCodegen( + '', + '', + 'with(this){var l0=__map(array,function(item,index){var $orig=__get_orig(item);var m0=test(index);return{$orig:$orig,m0:m0}});$mp.data=Object.assign({},{$root:{l0:l0}})}' + ) }) it('generate object property on custom component', () => { diff --git a/packages/uni-template-compiler/lib/script/traverse/data/model.js b/packages/uni-template-compiler/lib/script/traverse/data/model.js index d5172ed41e240cb660e2c6b28f57f24174efaa6d..37097c68bdd5207ee1fb4ad1882a4af7a9e5e85a 100644 --- a/packages/uni-template-compiler/lib/script/traverse/data/model.js +++ b/packages/uni-template-compiler/lib/script/traverse/data/model.js @@ -10,7 +10,9 @@ module.exports = function processRef (paths, path, state) { const callbackProperty = modelPath.node.value.properties.find(property => { return property.key.name === 'callback' }) - + const valueProperty = modelPath.node.value.properties.find( + property => property.key.name === 'value' + ) const exprProperty = modelPath.node.value.properties.find( property => property.key.name === 'expression' ) @@ -63,9 +65,9 @@ module.exports = function processRef (paths, path, state) { return [ // attrs:{value:value} t.objectProperty( t.stringLiteral(process.env.UNI_USING_VUE3 ? 'modelValue' : 'value'), - t.identifier(prop) + valueProperty.value ) ] } return [] -} +} diff --git a/packages/vue-cli-plugin-uni/lib/configure-webpack.js b/packages/vue-cli-plugin-uni/lib/configure-webpack.js index 59168a560e6ab2b3bd2b07f654e5e0d600e0e72b..307619935ed1c60bbc9b2b931396fc19b6f0a86d 100644 --- a/packages/vue-cli-plugin-uni/lib/configure-webpack.js +++ b/packages/vue-cli-plugin-uni/lib/configure-webpack.js @@ -186,13 +186,10 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt if (babelLoader) { const options = api.genCacheConfig('babel-loader/' + process.env.UNI_PLATFORM, getPartialIdentifier()) if (webpack.version[0] > 4) { - if (process.env.UNI_USING_CACHE) { - Object.assign(babelLoader.options, options) - } else { - Object.assign(babelLoader.options, { - cacheDirectory: false - }) - } + babelLoader.options = babelLoader.options || {} + Object.assign(babelLoader.options, process.env.UNI_USING_CACHE ? options : { + cacheDirectory: false + }) } else { const index = uses.findIndex(use => cacheLoaderRe.test(use.loader)) if (index >= 0) { diff --git a/packages/vue-cli-plugin-uni/lib/copy-webpack-options.js b/packages/vue-cli-plugin-uni/lib/copy-webpack-options.js index 514ef6d4b6b43b8272de8d547fdc4cf1e0790a87..76d7e9e5e1228c01d7ad643ba13ffa54f7e8fbe9 100644 --- a/packages/vue-cli-plugin-uni/lib/copy-webpack-options.js +++ b/packages/vue-cli-plugin-uni/lib/copy-webpack-options.js @@ -92,12 +92,16 @@ function getCopyWebpackPluginOptions (platformOptions, vueOptions) { }) // 自动化测试时,不启用androidPrivacy.json if (process.env.UNI_PLATFORM === 'app-plus' && !process.env.UNI_AUTOMATOR_WS_ENDPOINT) { - copyOptions.push({ - from: path.resolve(process.env.UNI_INPUT_DIR, 'android*.json'), + const from = 'android*.json' + const fileName = 'androidPrivacy.json' + const context = path.resolve(process.env.UNI_INPUT_DIR) + const options = { + from, + context, to: `[name]${CopyWebpackPluginVersion > 5 ? '' : '.'}[ext]`, noErrorOnMissing: true, transform (content, path) { - if (path.endsWith('androidPrivacy.json')) { + if (path.endsWith(fileName)) { const options = initI18nOptions( process.env.UNI_PLATFORM, process.env.UNI_INPUT_DIR, @@ -111,7 +115,21 @@ function getCopyWebpackPluginOptions (platformOptions, vueOptions) { } return content } - }) + } + // copy-webpack-plugin/glob-parent 存在 Bug,例如:/test/dir(1 + const globParent = require(require.resolve('glob-parent', { paths: [require.resolve('copy-webpack-plugin')] })) + const parent = globParent(path.join(context, from)) + let canNotWatch + if (parent !== context) { + options.from = fileName + if (!fs.existsSync(path.join(context, fileName))) { + canNotWatch = true + // console.warn(`invalid path: ${context}, can not watch ${fileName}`) + } + } + if (!canNotWatch) { + copyOptions.push(options) + } } return copyOptions } diff --git a/packages/vue-cli-plugin-uni/lib/error-reporting.js b/packages/vue-cli-plugin-uni/lib/error-reporting.js index fb535f0eb1f6c38df7b174b7f74aa7e78b86c786..564ae0c88a1ca1fad2af8964d51650ecad332b70 100644 --- a/packages/vue-cli-plugin-uni/lib/error-reporting.js +++ b/packages/vue-cli-plugin-uni/lib/error-reporting.js @@ -1,5 +1,5 @@ const { - normalizePath, + pathToRegexp, isInHBuilderX } = require('@dcloudio/uni-cli-shared/lib/util') const plp = require('@dcloudio/webpack-uni-pages-loader/package.json') @@ -18,8 +18,8 @@ class ErrorReport { this._https = null this._crypto = null this._cacheList = [] - this._UNI_INPUT_DIR_REG = new RegExp(normalizePath(process.env.UNI_INPUT_DIR), 'g') - this._UNI_CLI_CONTEXT_REG = new RegExp(normalizePath(process.env.UNI_CLI_CONTEXT), 'g') + this._UNI_INPUT_DIR_REG = pathToRegexp(process.env.UNI_INPUT_DIR, { global: true }) + this._UNI_CLI_CONTEXT_REG = pathToRegexp(process.env.UNI_CLI_CONTEXT, { global: true }) } get os () { @@ -47,7 +47,6 @@ class ErrorReport { } catch (e) {} } - err = normalizePath(err) || '' err = err.replace(this._UNI_INPUT_DIR_REG, 'UNI_INPUT_DIR') err = err.replace(this._UNI_CLI_CONTEXT_REG, 'UNI_CLI_CONTEXT') diff --git a/packages/vue-cli-plugin-uni/lib/options.js b/packages/vue-cli-plugin-uni/lib/options.js index 25ef468a8511efa098d2fb9a1798a46905ae2629..85a1ca7b7947aadf41ce70971f66cb47b27a7fc9 100644 --- a/packages/vue-cli-plugin-uni/lib/options.js +++ b/packages/vue-cli-plugin-uni/lib/options.js @@ -1,14 +1,9 @@ const fs = require('fs') const path = require('path') const webpack = require('webpack') - -const isWin = /^win/.test(process.platform) - -function genTranspileDepRegex (depPath) { - return new RegExp(isWin - ? depPath.replace(/\\/g, '\\\\') // double escape for windows style path - : depPath) -} +const { + pathToRegexp +} = require('@dcloudio/uni-cli-shared/lib/util') module.exports = function initOptions (options) { const { @@ -21,7 +16,7 @@ module.exports = function initOptions (options) { } // 增加 src/node_modules 解析 - options.transpileDependencies.push(genTranspileDepRegex(path.resolve(process.env.UNI_INPUT_DIR, 'node_modules'))) + options.transpileDependencies.push(pathToRegexp(path.resolve(process.env.UNI_INPUT_DIR, 'node_modules'), { start: true })) options.transpileDependencies.push('@dcloudio/uni-' + process.env.UNI_PLATFORM) options.transpileDependencies.push('@dcloudio/uni-i18n') options.transpileDependencies.push('@dcloudio/uni-stat') diff --git a/packages/vue-cli-plugin-uni/lib/util.js b/packages/vue-cli-plugin-uni/lib/util.js index 1c0e0a30a7c8b3e63b94ab9da97bdd0f90b180e9..cc9cd9d5d3c852a2ea02dae7809d2988ab7c57c1 100644 --- a/packages/vue-cli-plugin-uni/lib/util.js +++ b/packages/vue-cli-plugin-uni/lib/util.js @@ -1,4 +1,8 @@ const path = require('path') +const { + pathToGlob +} = require('@dcloudio/uni-cli-shared/lib/util') + let partialIdentifier = false module.exports = { getPartialIdentifier () { @@ -21,7 +25,7 @@ module.exports = { getWatchOptions () { return { ignored: [ - path.resolve(process.env.UNI_INPUT_DIR, '*.md'), + pathToGlob(path.resolve(process.env.UNI_INPUT_DIR), '*.md'), path.resolve(process.env.UNI_INPUT_DIR, '.hbuilderx'), path.resolve(process.env.UNI_INPUT_DIR, '.editorconfig'), path.resolve(process.env.UNI_INPUT_DIR, '.gitignore'), diff --git a/packages/vue-cli-plugin-uni/packages/uni-push/dist/uni-push.es.js b/packages/vue-cli-plugin-uni/packages/uni-push/dist/uni-push.es.js index 3e81464982f47eb13259948bd6f965c44bcfffee..102aa2f893f3ea8c66490b807dd9078bb5525bb5 100644 --- a/packages/vue-cli-plugin-uni/packages/uni-push/dist/uni-push.es.js +++ b/packages/vue-cli-plugin-uni/packages/uni-push/dist/uni-push.es.js @@ -111,7 +111,9 @@ function initPushNotification() { }); }); uni.onPushMessage((res) => { - if (res.type === 'receive' && res.data && res.data.force_notification) { + if (res.type === 'receive' && + res.data && + res.data.force_notification) { // 创建通知栏 uni.createPushMessage(res.data); res.stopped = true; diff --git a/packages/vue-cli-plugin-uni/packages/uni-push/dist/uni-push.plus.es.js b/packages/vue-cli-plugin-uni/packages/uni-push/dist/uni-push.plus.es.js index 4b2a5c93f911c289b99191c7f6b98ed1dd848700..e30c14a76f5c4d78de5d5004a34f958897a42484 100644 --- a/packages/vue-cli-plugin-uni/packages/uni-push/dist/uni-push.plus.es.js +++ b/packages/vue-cli-plugin-uni/packages/uni-push/dist/uni-push.plus.es.js @@ -1,25 +1,10 @@ // @ts-expect-error uni.invokePushCallback({ type: 'enabled', + offline: true, }); Promise.resolve().then(() => { plus.push.setAutoNotification && plus.push.setAutoNotification(false); - plus.push.getClientInfoAsync((info) => { - if (info.clientid) { - // @ts-expect-error - uni.invokePushCallback({ - type: 'clientId', - cid: info.clientid, - }); - } - }, (res) => { - // @ts-expect-error - uni.invokePushCallback({ - type: 'clientId', - cid: '', - errMsg: res.code + ': ' + res.message, - }); - }); plus.push.addEventListener('click', (result) => { // @ts-expect-error uni.invokePushCallback({ diff --git a/packages/webpack-uni-pages-loader/lib/platforms/h5.js b/packages/webpack-uni-pages-loader/lib/platforms/h5.js index a38e799f36d452dc5cb751972527a0eb1f87e738..72feaf423b9479221485da70659ccb68503a5b0d 100644 --- a/packages/webpack-uni-pages-loader/lib/platforms/h5.js +++ b/packages/webpack-uni-pages-loader/lib/platforms/h5.js @@ -177,7 +177,7 @@ const genRegisterPageVueComponentsCode = function (pageComponents) { return `Vue.component('${name}', resolve=>{ const component = { - component:require.ensure([], () => resolve(require('${path}${ext}')), '${name}'), + component:require.ensure([], () => resolve(require(${JSON.stringify(path)}+'${ext}')), '${name}'), delay:__uniConfig['async'].delay, timeout: __uniConfig['async'].timeout } diff --git a/yarn.lock b/yarn.lock index 35eedd6d3adbceb0cefae6bdd964e7b5cc05d985..26f33ccc41a8248ffe4eeb05997b3838d45dfd0c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3433,6 +3433,11 @@ escape-string-regexp@1.0.5, escape-string-regexp@^1.0.2, escape-string-regexp@^1 version "1.0.5" resolved "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" +escape-string-regexp@4: + version "4.0.0" + resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz#14ba83a5d373e3d311e5afca29cf5bfad965bf34" + integrity sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA== + escodegen@^1.11.1, escodegen@^1.14.1: version "1.14.1" resolved "https://registry.npmjs.org/escodegen/-/escodegen-1.14.1.tgz#ba01d0c8278b5e95a9a45350142026659027a457" @@ -4215,6 +4220,11 @@ getpass@^0.1.1: dependencies: assert-plus "^1.0.0" +glob-escape@^0.0.2: + version "0.0.2" + resolved "https://registry.yarnpkg.com/glob-escape/-/glob-escape-0.0.2.tgz#9c27f7821ed1c1377582f3efd9558e3f675628ed" + integrity sha512-L/cXYz8x7qer1HAyUQ+mbjcUsJVdpRxpAf7CwqHoNBs9vTpABlGfNN4tzkDxt+u3Z7ZncVyKlCNPtzb0R/7WbA== + glob-parent@5.1.0: version "5.1.0" resolved "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.0.tgz#5f4c1d1e748d30cd73ad2944b3577a81b081e8c2"