Skip to content

Commit

Permalink
Merge pull request #66 from mpx-ecology/bugfix/web-inspect
Browse files Browse the repository at this point in the history
fix: web inspect
  • Loading branch information
mater1996 authored Jun 28, 2023
2 parents d22e89d + 4b95e8c commit 4de73b6
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 40 deletions.
24 changes: 24 additions & 0 deletions packages/mpx-cli/__tests__/preset.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,30 @@ 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',
appid: 'dd-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目录
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/mpx-cli/lib/prompts.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ module.exports = [
},
{
name: 'appid',
when: ({ srcMode }) => srcMode === 'wx',
when: ({ srcMode }) => srcMode === 'wx' || srcMode === 'dd',
required: true,
message: '请输入小程序的Appid',
default: 'touristappid'
Expand Down
13 changes: 3 additions & 10 deletions packages/vue-cli-plugin-mpx/commands/build/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')(
Expand All @@ -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
Expand All @@ -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
})
)
Expand Down
48 changes: 22 additions & 26 deletions packages/vue-cli-plugin-mpx/commands/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,31 @@ 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' }))
}
)
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(
Expand All @@ -59,16 +52,19 @@ 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,
MPX_CURRENT_TARGET_MODE: target.mode,
MPX_CURRENT_TARGET_ENV: target.env,
NODE_ENV: undefined
},
stdio: 'inherit'
}
)
}
}
)
Expand Down
2 changes: 1 addition & 1 deletion packages/vue-cli-plugin-mpx/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ module.exports.defaultModes = {
'serve:mp': 'development',
'serve:web': 'development',
'build:mp': 'production',
'build:web': 'development'
'build:web': 'production'
}
1 change: 1 addition & 0 deletions packages/vue-cli-plugin-mpx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 1 addition & 2 deletions packages/vue-cli-plugin-mpx/utils/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ module.exports.handleWebpackDone = function (err, stats, target) {
? 'with some warnings'
: 'successfully'
const result = []
if (hasErrors) result.push(extractResultFromStats(stats))
if (hasWarnings) result.push(extractErrorsFromStats(stats, 'warnings'))
if (hasErrors) result.push(extractErrorsFromStats(stats))
if (!hasErrors) result.push(extractResultFromStats(stats))
getReporter()._renderStates(
stats.stats.map((v) => {
Expand Down

0 comments on commit 4de73b6

Please sign in to comment.