diff --git a/packages/uni-app-vite/package.json b/packages/uni-app-vite/package.json index e6cf9a17abaf8ab1b48602de70e5da5baf8026f2..c4476b851740e150412f8693d36f3ac4602e5cec 100644 --- a/packages/uni-app-vite/package.json +++ b/packages/uni-app-vite/package.json @@ -25,6 +25,7 @@ "@dcloudio/uni-shared": "3.0.0-alpha-3021320211109003", "@rollup/pluginutils": "^4.1.1", "clean-css": "^5.1.3", + "debug": "^4.3.2", "fs-extra": "^10.0.0", "postcss-import": "^14.0.2", "postcss-load-config": "^3.1.0", diff --git a/packages/uni-cli-shared/src/hbx/env.ts b/packages/uni-cli-shared/src/hbx/env.ts index d1bcbdbf36e044f9d4264bf1f535cf0078880658..fe18574ecb210308a130b63cc6063c30fd29d6cf 100644 --- a/packages/uni-cli-shared/src/hbx/env.ts +++ b/packages/uni-cli-shared/src/hbx/env.ts @@ -8,7 +8,10 @@ export const isInHBuilderX = once(() => { process.cwd(), '../about/package.json' )) - return name === 'about' + if (name === 'about') { + process.env.UNI_HBUILDERX_PLUGINS = path.resolve(process.cwd(), '..') + return true + } } catch (e) { // console.error(e) } diff --git a/packages/uni-h5-vite/package.json b/packages/uni-h5-vite/package.json index 4058ce27c2d8b5fae3f7f71e40753a46609cab82..0ba98b9d171565498657a01b73a0e7691e7d9976 100644 --- a/packages/uni-h5-vite/package.json +++ b/packages/uni-h5-vite/package.json @@ -24,9 +24,13 @@ "@rollup/pluginutils": "^4.1.1", "@vue/compiler-dom": "3.2.21", "@vue/compiler-sfc": "3.2.21", - "@vue/server-renderer": "3.2.21" + "@vue/server-renderer": "3.2.21", + "debug": "^4.3.2", + "mime": "^3.0.0", + "module-alias": "^2.2.2" }, "devDependencies": { + "@types/mime": "^2.0.3", "@vue/compiler-core": "3.2.21", "esbuild": "^0.13.2" } diff --git a/packages/uni-mp-vite/package.json b/packages/uni-mp-vite/package.json index 5d6a8f162df36e5c8bc0ae4820b9ffed6fc6009c..189fb4283adf999f3e4a6be990026c6dcc7c6cdb 100644 --- a/packages/uni-mp-vite/package.json +++ b/packages/uni-mp-vite/package.json @@ -23,6 +23,7 @@ "@dcloudio/uni-mp-vue": "3.0.0-alpha-3021320211109003", "@dcloudio/uni-shared": "3.0.0-alpha-3021320211109003", "base64url": "^3.0.1", + "debug": "^4.3.2", "magic-string": "^0.25.7" }, "gitHead": "33e807d66e1fe47e2ee08ad9c59247e37b8884da", diff --git a/packages/uni-stat/build.json b/packages/uni-stat/build.json index fe480ebdf13b6bd6e5f35eb1cdd88f163df5f9c4..9757c63316b9ced28bc7276520ff130710e2eb99 100644 --- a/packages/uni-stat/build.json +++ b/packages/uni-stat/build.json @@ -1,5 +1,16 @@ -{ - "input": { - "src/index.js": ["dist/uni-stat.es.js", "dist/uni-stat.cjs.js"] +[ + { + "input": { + "src/plugin/index.ts": "lib/uni.plugin.js" + }, + "output": { + "format": "cjs" + }, + "external": ["debug", "@dcloudio/uni-cli-shared"] + }, + { + "input": { + "src/index.js": ["dist/uni-stat.es.js", "dist/uni-stat.cjs.js"] + } } -} +] diff --git a/packages/uni-stat/lib/uni.plugin.js b/packages/uni-stat/lib/uni.plugin.js index d29b4832ae013652480c6d599eb6ec2faf2fe3dc..3d324b1defca999f4f1db711a2585bb9d1bf33eb 100644 --- a/packages/uni-stat/lib/uni.plugin.js +++ b/packages/uni-stat/lib/uni.plugin.js @@ -1,14 +1,16 @@ -const debug = require('debug') -const { - M, - defineUniMainJsPlugin, - getUniStatistics, - parseManifestJsonOnce, - parsePagesJsonOnce, -} = require('@dcloudio/uni-cli-shared') +'use strict' -module.exports = [ - defineUniMainJsPlugin((opts) => { +var debug = require('debug') +var uniCliShared = require('@dcloudio/uni-cli-shared') + +function _interopDefaultLegacy(e) { + return e && typeof e === 'object' && 'default' in e ? e : { default: e } +} + +var debug__default = /*#__PURE__*/ _interopDefaultLegacy(debug) + +var index = [ + uniCliShared.defineUniMainJsPlugin((opts) => { let isEnable = false return { name: 'vite:uni-stat', @@ -19,26 +21,29 @@ module.exports = [ } const inputDir = process.env.UNI_INPUT_DIR const platform = process.env.UNI_PLATFORM - isEnable = getUniStatistics(inputDir, platform).enable === true + isEnable = + uniCliShared.getUniStatistics(inputDir, platform).enable === true if (process.env.NODE_ENV === 'production') { - const manifestJson = parseManifestJsonOnce(inputDir) + const manifestJson = uniCliShared.parseManifestJsonOnce(inputDir) if (!manifestJson.appid) { console.log() - console.warn(M['stat.warn.appid']) + console.warn(uniCliShared.M['stat.warn.appid']) console.log() isEnable = false } } const titlesJson = Object.create(null) if (isEnable) { - parsePagesJsonOnce(inputDir, platform).pages.forEach((page) => { - const titleText = page.style.navigationBar.titleText || '' - if (titleText) { - titlesJson[page.path] = titleText - } - }) + uniCliShared + .parsePagesJsonOnce(inputDir, platform) + .pages.forEach((page) => { + const titleText = page.style.navigationBar.titleText || '' + if (titleText) { + titlesJson[page.path] = titleText + } + }) } - debug('vite:uni:stat')('isEnable', isEnable) + debug__default['default']('vite:uni:stat')('isEnable', isEnable) process.env.UNI_STAT_TITLE_JSON = JSON.stringify(titlesJson) return { define: { @@ -57,7 +62,6 @@ module.exports = [ } }), ] - function isSsr(command, config) { if (command === 'serve') { return !!(config.server && config.server.middlewareMode) @@ -67,3 +71,5 @@ function isSsr(command, config) { } return false } + +module.exports = index diff --git a/packages/uni-stat/package.json b/packages/uni-stat/package.json index a19f1bff61f8a88b4aef1f437b0398ba11e754cd..7f7f078cf37793eda19d0e94411b9fef6bd00dcf 100644 --- a/packages/uni-stat/package.json +++ b/packages/uni-stat/package.json @@ -18,5 +18,9 @@ "bugs": { "url": "https://github.com/dcloudio/uni-app/issues" }, - "gitHead": "33e807d66e1fe47e2ee08ad9c59247e37b8884da" + "gitHead": "33e807d66e1fe47e2ee08ad9c59247e37b8884da", + "dependencies": { + "@dcloudio/uni-cli-shared": "workspace:3.0.0-alpha-3021320211109003", + "debug": "^4.3.2" + } } diff --git a/packages/uni-stat/src/plugin/index.ts b/packages/uni-stat/src/plugin/index.ts new file mode 100644 index 0000000000000000000000000000000000000000..360a236a81325c2edbac1d86b5ea36fd2f3da011 --- /dev/null +++ b/packages/uni-stat/src/plugin/index.ts @@ -0,0 +1,70 @@ +import type { ConfigEnv, UserConfig } from 'vite' +import debug from 'debug' +import { + M, + defineUniMainJsPlugin, + getUniStatistics, + parseManifestJsonOnce, + parsePagesJsonOnce, +} from '@dcloudio/uni-cli-shared' + +export default [ + defineUniMainJsPlugin((opts) => { + let isEnable = false + return { + name: 'vite:uni-stat', + enforce: 'pre', + config(config, env) { + if (isSsr(env.command, config)) { + return + } + const inputDir = process.env.UNI_INPUT_DIR! + const platform = process.env.UNI_PLATFORM! + isEnable = getUniStatistics(inputDir, platform).enable === true + if (process.env.NODE_ENV === 'production') { + const manifestJson = parseManifestJsonOnce(inputDir) + if (!manifestJson.appid) { + console.log() + console.warn(M['stat.warn.appid']) + console.log() + isEnable = false + } + } + const titlesJson = Object.create(null) + if (isEnable) { + parsePagesJsonOnce(inputDir, platform).pages.forEach((page: any) => { + const titleText = page.style.navigationBar.titleText || '' + if (titleText) { + titlesJson[page.path] = titleText + } + }) + } + debug('vite:uni:stat')('isEnable', isEnable) + process.env.UNI_STAT_TITLE_JSON = JSON.stringify(titlesJson) + return { + define: { + 'process.env.UNI_STAT_TITLE_JSON': process.env.UNI_STAT_TITLE_JSON, + }, + } + }, + transform(code, id) { + if (isEnable && opts.filter(id)) { + return { + code: code + `;import '@dcloudio/uni-stat';`, + map: null, + } + } + }, + } + }), +] + +function isSsr(command: ConfigEnv['command'], config: UserConfig) { + if (command === 'serve') { + return !!(config.server && config.server.middlewareMode) + } + if (command === 'build') { + return !!(config.build && config.build.ssr) + } + return false +} diff --git a/packages/vite-plugin-uni/package.json b/packages/vite-plugin-uni/package.json index a8309374ebd142eea2ef2fc60db5e21fea8ec0f2..0c27fb2562a00399f4708de83aa91f882a794a88 100644 --- a/packages/vite-plugin-uni/package.json +++ b/packages/vite-plugin-uni/package.json @@ -36,14 +36,10 @@ "estree-walker": "^2.0.2", "express": "^4.17.1", "fs-extra": "^10.0.0", - "jsonc-parser": "^3.0.0", - "mime": "^2.5.2", - "module-alias": "^2.2.2" + "jsonc-parser": "^3.0.0" }, "devDependencies": { "@types/express": "^4.17.12", - "@types/mime": "^2.0.3", - "@types/module-alias": "^2.0.0", "@types/sass": "^1.16.0", "@vue/babel-plugin-jsx": "^1.1.1", "chokidar": "^3.5.2" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0db0cf4fbe62c586019f9901dfbad5f2b09f2946..f7fb5ec7b317f18da920bb0e7a31ecba8eee6de7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -197,6 +197,7 @@ importers: '@rollup/pluginutils': ^4.1.1 '@vue/compiler-core': 3.2.21 clean-css: ^5.1.3 + debug: ^4.3.2 fs-extra: ^10.0.0 postcss-import: ^14.0.2 postcss-load-config: ^3.1.0 @@ -208,6 +209,7 @@ importers: '@dcloudio/uni-shared': link:../uni-shared '@rollup/pluginutils': 4.1.1 clean-css: 5.2.2 + debug: 4.3.2 fs-extra: 10.0.0 postcss-import: 14.0.2 postcss-load-config: 3.1.0 @@ -268,6 +270,7 @@ importers: loader-utils: ^1.1.0 lru-cache: ^4.1.2 merge-source-map: ^1.1.0 + module-alias: ^2.2.2 postcss: ^8.3.8 postcss-comment: ^2.0.0 postcss-import: ^14.0.2 @@ -305,6 +308,7 @@ importers: loader-utils: 1.4.0 lru-cache: 4.1.5 merge-source-map: 1.1.0 + module-alias: 2.2.2 postcss: 8.3.11 postcss-comment: 2.0.0 postcss-import: 14.0.2_postcss@8.3.11 @@ -336,6 +340,7 @@ importers: '@rollup/pluginutils': ^4.1.1 '@types/hash-sum': ^1.0.0 '@types/less': ^3.0.3 + '@types/mime': ^2.0.3 '@types/stylus': ^0.48.36 '@vue/compiler-core': 3.2.21 '@vue/compiler-dom': 3.2.21 @@ -352,6 +357,8 @@ importers: jsonc-parser: ^3.0.0 magic-string: ^0.25.7 merge: ^2.1.1 + mime: ^3.0.0 + module-alias: ^2.2.2 postcss: ^8.3.8 postcss-import: ^14.0.2 postcss-load-config: ^3.1.0 @@ -379,6 +386,8 @@ importers: jsonc-parser: 3.0.0 magic-string: 0.25.7 merge: 2.1.1 + mime: 3.0.0 + module-alias: 2.2.2 postcss-import: 14.0.2_postcss@8.3.11 postcss-load-config: 3.1.0 postcss-selector-parser: 6.0.6 @@ -388,6 +397,7 @@ importers: devDependencies: '@types/hash-sum': 1.0.0 '@types/less': 3.0.3 + '@types/mime': 2.0.3 '@types/stylus': 0.48.36 '@vue/compiler-sfc': 3.2.21 postcss: 8.3.11 @@ -458,11 +468,15 @@ importers: '@dcloudio/uni-cli-shared': 3.0.0-alpha-3021320211109003 '@dcloudio/uni-shared': 3.0.0-alpha-3021320211109003 '@rollup/pluginutils': ^4.1.1 + '@types/mime': ^2.0.3 '@vue/compiler-core': 3.2.21 '@vue/compiler-dom': 3.2.21 '@vue/compiler-sfc': 3.2.21 '@vue/server-renderer': 3.2.21 + debug: ^4.3.2 esbuild: ^0.13.2 + mime: ^3.0.0 + module-alias: ^2.2.2 dependencies: '@dcloudio/uni-cli-shared': link:../uni-cli-shared '@dcloudio/uni-shared': link:../uni-shared @@ -470,7 +484,11 @@ importers: '@vue/compiler-dom': 3.2.21 '@vue/compiler-sfc': 3.2.21 '@vue/server-renderer': 3.2.21_vue@3.2.21 + debug: 4.3.2 + mime: 3.0.0 + module-alias: 2.2.2 devDependencies: + '@types/mime': 2.0.3 '@vue/compiler-core': 3.2.21 esbuild: 0.13.12 @@ -607,6 +625,7 @@ importers: '@dcloudio/uni-shared': 3.0.0-alpha-3021320211109003 '@vue/compiler-sfc': 3.2.21 base64url: ^3.0.1 + debug: ^4.3.2 magic-string: ^0.25.7 dependencies: '@dcloudio/uni-cli-shared': link:../uni-cli-shared @@ -614,6 +633,7 @@ importers: '@dcloudio/uni-mp-vue': link:../uni-mp-vue '@dcloudio/uni-shared': link:../uni-shared base64url: 3.0.1 + debug: 4.3.2 magic-string: 0.25.7 devDependencies: '@vue/compiler-sfc': 3.2.21 @@ -657,7 +677,12 @@ importers: '@vue/runtime-core': 3.2.21 packages/uni-stat: - specifiers: {} + specifiers: + '@dcloudio/uni-cli-shared': workspace:3.0.0-alpha-3021320211109003 + debug: ^4.3.2 + dependencies: + '@dcloudio/uni-cli-shared': link:../uni-cli-shared + debug: 4.3.2 packages/uni-vue: specifiers: @@ -673,8 +698,6 @@ importers: '@dcloudio/uni-shared': 3.0.0-alpha-3021320211109003 '@rollup/pluginutils': ^4.1.1 '@types/express': ^4.17.12 - '@types/mime': ^2.0.3 - '@types/module-alias': ^2.0.0 '@types/sass': ^1.16.0 '@vitejs/plugin-legacy': ^1.6.2 '@vitejs/plugin-vue': ^1.9.4 @@ -690,8 +713,6 @@ importers: express: ^4.17.1 fs-extra: ^10.0.0 jsonc-parser: ^3.0.0 - mime: ^2.5.2 - module-alias: ^2.2.2 dependencies: '@dcloudio/uni-cli-shared': link:../uni-cli-shared '@dcloudio/uni-shared': link:../uni-shared @@ -708,12 +729,8 @@ importers: express: 4.17.1 fs-extra: 10.0.0 jsonc-parser: 3.0.0 - mime: 2.6.0 - module-alias: 2.2.2 devDependencies: '@types/express': 4.17.13 - '@types/mime': 2.0.3 - '@types/module-alias': 2.0.1 '@types/sass': 1.43.0 '@vue/babel-plugin-jsx': 1.1.1 chokidar: 3.5.2 @@ -2554,10 +2571,6 @@ packages: resolution: {integrity: sha512-Klz949h02Gz2uZCMGwDUSDS1YBlTdDDgbWHi+81l29tQALUtvz4rAYi5uoVhE5Lagoq6DeqAUlbrHvW/mXDgdQ==} dev: false - /@types/module-alias/2.0.1: - resolution: {integrity: sha512-DN/CCT1HQG6HquBNJdLkvV+4v5l/oEuwOHUPLxI+Eub0NED+lk0YUfba04WGH90EINiUrNgClkNnwGmbICeWMQ==} - dev: true - /@types/ms/0.7.31: resolution: {integrity: sha512-iiUgKzV9AuaEkZqkOLDIvlQiL6ltuZd9tGcW3gwpnX8JbuiuhFlEGmmFXEXkN50Cvq7Os88IY2v0dkDqXYWVgA==} dev: true @@ -6623,9 +6636,9 @@ packages: hasBin: true requiresBuild: true - /mime/2.6.0: - resolution: {integrity: sha512-USPkMeET31rOMiarsBNIHZKLGgvKc/LrjofAnBlOttf5ajRvqiRA8QsenbcooctK6d6Ts6aqZXBA+XbkKthiQg==} - engines: {node: '>=4.0.0'} + /mime/3.0.0: + resolution: {integrity: sha512-jSCU7/VB1loIWBZe14aEYHU/+1UMEHoaO7qxCOVJOw9GgH72VAWppxNcjU+x9a2k3GSIBXNKxXQFqRvvZ7vr3A==} + engines: {node: '>=10.0.0'} hasBin: true dev: false