From 3fc851bbb5472de6b2ce73bc2e06569937fc7dd3 Mon Sep 17 00:00:00 2001 From: Mater Date: Tue, 13 Jun 2023 20:33:05 +0800 Subject: [PATCH 1/5] fix: web inspect --- .../vue-cli-plugin-mpx/commands/build/web.js | 13 ++--- .../vue-cli-plugin-mpx/commands/inspect.js | 49 +++++++++---------- packages/vue-cli-plugin-mpx/index.js | 2 +- packages/vue-cli-plugin-mpx/package.json | 1 + packages/vue-cli-plugin-mpx/utils/webpack.js | 3 +- 5 files changed, 29 insertions(+), 39 deletions(-) diff --git a/packages/vue-cli-plugin-mpx/commands/build/web.js b/packages/vue-cli-plugin-mpx/commands/build/web.js index 6abb25c5..b89da7d6 100644 --- a/packages/vue-cli-plugin-mpx/commands/build/web.js +++ b/packages/vue-cli-plugin-mpx/commands/build/web.js @@ -4,7 +4,6 @@ const { getCurrentTarget } = require('../../utils') const resolveWebBuildWebpackConfig = (api, options, args) => { const validateWebpackConfig = require('@vue/cli-service/lib/util/validateWebpackConfig') - const isLegacyBuild = args.needsDifferentialLoading && !args.moduleBuild // resolve raw webpack config const webpackConfig = require('@vue/cli-service/lib/commands/build/resolveAppConfig')( @@ -13,7 +12,7 @@ const resolveWebBuildWebpackConfig = (api, options, args) => { options ) // check for common config errors - validateWebpackConfig(webpackConfig, api, options, args.target) + validateWebpackConfig(webpackConfig, api, options) if (args.watch) { modifyConfig(webpackConfig, (config) => { config.watch = true @@ -22,19 +21,13 @@ const resolveWebBuildWebpackConfig = (api, options, args) => { if (args.report) { const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer') modifyConfig(webpackConfig, (config) => { - const bundleName = - args.target !== 'app' - ? config.output.filename.replace(/\.js$/, '-') - : isLegacyBuild - ? 'legacy-' - : '' config.plugins.push( new BundleAnalyzerPlugin({ logLevel: 'warn', openAnalyzer: false, analyzerMode: args.report ? 'static' : 'disabled', - reportFilename: `${bundleName}report.html`, - statsFilename: `${bundleName}report.json`, + reportFilename: 'report.html', + statsFilename: 'report.json', generateStatsFile: !!args.report }) ) diff --git a/packages/vue-cli-plugin-mpx/commands/inspect.js b/packages/vue-cli-plugin-mpx/commands/inspect.js index 84e6344b..c1a8876d 100644 --- a/packages/vue-cli-plugin-mpx/commands/inspect.js +++ b/packages/vue-cli-plugin-mpx/commands/inspect.js @@ -15,26 +15,14 @@ module.exports.registerInspectCommand = function registerInspectCommand ( api.registerCommand( 'inspect:mp', { - description: 'inspect', + description: 'inspect mp', usage: 'mpx-cli-service inspect:mp' }, (args, rawArgs) => { const target = getCurrentTarget() - if ((args.targets && !target.mode) || !target.mode) { - return api.service.commands.inspect.fn(args, rawArgs) - } const { verbose } = args if (target.env) process.env.NODE_ENV = target.env - const res = - target.mode === 'web' - ? resolveWebBuildWebpackConfig(api, options, { - ...args, - target: `${target.mode}:${target.env}` - }) - : resolveMpBuildWebpackConfig(api, options, { - ...args, - target: `${target.mode}:${target.env}` - }) + const res = resolveMpBuildWebpackConfig(api, options, args) const output = toString(res, { verbose }) console.log(highlight(output, { language: 'js' })) } @@ -42,11 +30,16 @@ module.exports.registerInspectCommand = function registerInspectCommand ( api.registerCommand( 'inspect:web', { - description: 'inspect', + description: 'inspect web', usage: 'mpx-cli-service inspect:web' }, (args, rawArgs) => { - return api.service.commands.inspect.fn({ args, targets: 'web' }, [...rawArgs, '--targets=web']) + const target = getCurrentTarget() + const { verbose } = args + if (target.env) process.env.NODE_ENV = target.env + const res = resolveWebBuildWebpackConfig(api, options, args) + const output = toString(res, { verbose }) + console.log(highlight(output, { language: 'js' })) } ) api.registerCommand( @@ -59,16 +52,20 @@ module.exports.registerInspectCommand = function registerInspectCommand ( const targets = getTargets(args, options) // 小程序业务代码构建配置 for (const target of targets) { - await runServiceCommand('inspect:mp', rawArgs, { - env: { - ...process.env, - FORCE_COLOR: true, - MPX_CURRENT_TARGET_MODE: target.mode, - MPX_CURRENT_TARGET_ENV: target.env, - NODE_ENV: undefined - }, - stdio: 'inherit' - }) + await runServiceCommand( + target.mode === 'web' ? 'inspect:web' : 'inspect:mp', + rawArgs, + { + env: { + ...process.env, + FORCE_COLOR: true, + MPX_CURRENT_TARGET_MODE: target.mode, + MPX_CURRENT_TARGET_ENV: target.env, + NODE_ENV: undefined + }, + stdio: 'inherit' + } + ) } } ) diff --git a/packages/vue-cli-plugin-mpx/index.js b/packages/vue-cli-plugin-mpx/index.js index 58d6542a..98194c6f 100644 --- a/packages/vue-cli-plugin-mpx/index.js +++ b/packages/vue-cli-plugin-mpx/index.js @@ -32,5 +32,5 @@ module.exports.defaultModes = { 'serve:mp': 'development', 'serve:web': 'development', 'build:mp': 'production', - 'build:web': 'development' + 'build:web': 'production' } diff --git a/packages/vue-cli-plugin-mpx/package.json b/packages/vue-cli-plugin-mpx/package.json index c0f1df97..3bd0b2c2 100644 --- a/packages/vue-cli-plugin-mpx/package.json +++ b/packages/vue-cli-plugin-mpx/package.json @@ -17,6 +17,7 @@ "copy-webpack-plugin": "^9.1.0", "cli-highlight": "^2.1.10", "execa": "^5.0.0", + "fs-extra": "^9.1.0", "launch-editor-middleware": "^2.2.1", "minimist": "^1.2.5", "portfinder": "^1.0.26", diff --git a/packages/vue-cli-plugin-mpx/utils/webpack.js b/packages/vue-cli-plugin-mpx/utils/webpack.js index 94b7732d..6df898fa 100644 --- a/packages/vue-cli-plugin-mpx/utils/webpack.js +++ b/packages/vue-cli-plugin-mpx/utils/webpack.js @@ -3,7 +3,7 @@ const { runServiceCommand } = require('./index') const { resolvePluginWebpackConfig } = require('../config/mp/plugin') const { resolveBaseRawWebpackConfig } = require('../config/mp/base') const { LogUpdate, getReporter } = require('./reporter') -const { extractResultFromStats, extractErrorsFromStats } = require('./output') +const { extractResultFromStats } = require('./output') /** * 获取基础配置通过构建目标,该方法会运行插件方法并增加默认配置 @@ -108,7 +108,6 @@ module.exports.handleWebpackDone = function (err, stats, target) { : 'successfully' const result = [] if (hasErrors) result.push(extractResultFromStats(stats)) - if (hasWarnings) result.push(extractErrorsFromStats(stats, 'warnings')) if (!hasErrors) result.push(extractResultFromStats(stats)) getReporter()._renderStates( stats.stats.map((v) => { From f155c53658afbfeab6bdc25ec0d488d1d115eb21 Mon Sep 17 00:00:00 2001 From: Mater Date: Wed, 14 Jun 2023 15:27:15 +0800 Subject: [PATCH 2/5] fix: error extract --- packages/vue-cli-plugin-mpx/utils/webpack.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/vue-cli-plugin-mpx/utils/webpack.js b/packages/vue-cli-plugin-mpx/utils/webpack.js index 6df898fa..38730bbe 100644 --- a/packages/vue-cli-plugin-mpx/utils/webpack.js +++ b/packages/vue-cli-plugin-mpx/utils/webpack.js @@ -3,7 +3,7 @@ const { runServiceCommand } = require('./index') const { resolvePluginWebpackConfig } = require('../config/mp/plugin') const { resolveBaseRawWebpackConfig } = require('../config/mp/base') const { LogUpdate, getReporter } = require('./reporter') -const { extractResultFromStats } = require('./output') +const { extractResultFromStats, extractErrorsFromStats } = require('./output') /** * 获取基础配置通过构建目标,该方法会运行插件方法并增加默认配置 @@ -107,7 +107,7 @@ module.exports.handleWebpackDone = function (err, stats, target) { ? 'with some warnings' : 'successfully' const result = [] - if (hasErrors) result.push(extractResultFromStats(stats)) + if (hasErrors) result.push(extractErrorsFromStats(stats)) if (!hasErrors) result.push(extractResultFromStats(stats)) getReporter()._renderStates( stats.stats.map((v) => { From 91710adf67f3bd7817b831e56ecf2c35e0cd8ae9 Mon Sep 17 00:00:00 2001 From: Mater Date: Wed, 14 Jun 2023 17:50:53 +0800 Subject: [PATCH 3/5] fix: remove force color --- packages/vue-cli-plugin-mpx/commands/inspect.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/vue-cli-plugin-mpx/commands/inspect.js b/packages/vue-cli-plugin-mpx/commands/inspect.js index c1a8876d..5a70391c 100644 --- a/packages/vue-cli-plugin-mpx/commands/inspect.js +++ b/packages/vue-cli-plugin-mpx/commands/inspect.js @@ -58,7 +58,6 @@ module.exports.registerInspectCommand = function registerInspectCommand ( { env: { ...process.env, - FORCE_COLOR: true, MPX_CURRENT_TARGET_MODE: target.mode, MPX_CURRENT_TARGET_ENV: target.env, NODE_ENV: undefined From 207aa3ed3204a65115f982681fc4251a9cf3e7b1 Mon Sep 17 00:00:00 2001 From: Mater Date: Tue, 27 Jun 2023 16:44:23 +0800 Subject: [PATCH 4/5] fix: dd mode appid undefined --- packages/mpx-cli/__tests__/preset.spec.js | 23 +++++++++++++++++++++++ packages/mpx-cli/lib/prompts.js | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/packages/mpx-cli/__tests__/preset.spec.js b/packages/mpx-cli/__tests__/preset.spec.js index 5429666e..acbe7bfa 100644 --- a/packages/mpx-cli/__tests__/preset.spec.js +++ b/packages/mpx-cli/__tests__/preset.spec.js @@ -28,6 +28,29 @@ test('normal', async () => { expect(pkg.devDependencies).toHaveProperty('@mpxjs/vue-cli-plugin-mpx') }) +test('normal-didi', async () => { + const cwd = path.resolve(__dirname, '../../test') + const name = 'test-normal-didi' + await create( + name, + { + force: true, + git: false, + cwd + }, + { + srcMode: 'dd', + description: 'test', + cross: true, + plugins: {}, + useConfigFiles: true + } + ) + + const pkg = require(path.resolve(cwd, name, 'package.json')) + expect(pkg.devDependencies).toHaveProperty('@mpxjs/vue-cli-plugin-mpx') +}) + /** * 非跨平台项目不生成static/ali目录 */ diff --git a/packages/mpx-cli/lib/prompts.js b/packages/mpx-cli/lib/prompts.js index cbf90011..ca518d5e 100644 --- a/packages/mpx-cli/lib/prompts.js +++ b/packages/mpx-cli/lib/prompts.js @@ -93,7 +93,7 @@ module.exports = [ }, { name: 'appid', - when: ({ srcMode }) => srcMode === 'wx', + when: ({ srcMode }) => srcMode === 'wx' || srcMode === 'dd', required: true, message: '请输入小程序的Appid', default: 'touristappid' From 4b95e8c22bc68cdbeb550791bcf3e1703dd00a20 Mon Sep 17 00:00:00 2001 From: Mater Date: Wed, 28 Jun 2023 10:22:35 +0800 Subject: [PATCH 5/5] fix: didi appid --- packages/mpx-cli/__tests__/preset.spec.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/mpx-cli/__tests__/preset.spec.js b/packages/mpx-cli/__tests__/preset.spec.js index acbe7bfa..8fb67e6b 100644 --- a/packages/mpx-cli/__tests__/preset.spec.js +++ b/packages/mpx-cli/__tests__/preset.spec.js @@ -41,6 +41,7 @@ test('normal-didi', async () => { { srcMode: 'dd', description: 'test', + appid: 'dd-test', cross: true, plugins: {}, useConfigFiles: true