@mpxjs/webpack-plugin 2.9.50 → 2.9.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -67,6 +67,7 @@ const { MPX_PROCESSED_FLAG, MPX_DISABLE_EXTRACTOR_CACHE } = require('./utils/con
67
67
  const isEmptyObject = require('./utils/is-empty-object')
68
68
  const DynamicPlugin = require('./resolver/DynamicPlugin')
69
69
  const { isReact, isWeb } = require('./utils/env')
70
+ const VirtualModulesPlugin = require('webpack-virtual-modules')
70
71
  require('./utils/check-core-version-match')
71
72
 
72
73
  const isProductionLikeMode = options => {
@@ -306,6 +307,20 @@ class MpxWebpackPlugin {
306
307
  // 将entry export标记为used且不可mangle,避免require.async生成的js chunk在生产环境下报错
307
308
  new FlagEntryExportAsUsedPlugin(true, 'entry').apply(compiler)
308
309
 
310
+ let __vfs = null
311
+ if (isWeb(this.options.mode)) {
312
+ for (const plugin of compiler.options.plugins) {
313
+ if (plugin instanceof VirtualModulesPlugin) {
314
+ __vfs = plugin
315
+ break
316
+ }
317
+ }
318
+ if (!__vfs) {
319
+ __vfs = new VirtualModulesPlugin()
320
+ compiler.options.plugins.push(__vfs)
321
+ }
322
+ }
323
+
309
324
  if (!isWeb(this.options.mode) && !isReact(this.options.mode)) {
310
325
  // 强制设置publicPath为'/'
311
326
  if (compiler.options.output.publicPath && compiler.options.output.publicPath !== publicPath) {
@@ -520,6 +535,16 @@ class MpxWebpackPlugin {
520
535
  }
521
536
  }
522
537
 
538
+ const checkDynamicEntryInfo = (compilation) => {
539
+ for (const packageName in mpx.dynamicEntryInfo) {
540
+ const entryMap = mpx.dynamicEntryInfo[packageName]
541
+ if (packageName !== 'main' && !entryMap.hasPage) {
542
+ // 引用未注册分包的所有资源
543
+ const resources = entryMap.entries.map(info => info.resource).join(',')
544
+ compilation.errors.push(new Error(`资源${resources}通过分包异步声明为${packageName}分包, 但${packageName}分包未注册或不存在相关页面!`))
545
+ }
546
+ }
547
+ }
523
548
  // 构建分包队列,在finishMake钩子当中最先执行,stage传递-1000
524
549
  compiler.hooks.finishMake.tapAsync({
525
550
  name: 'MpxWebpackPlugin',
@@ -534,17 +559,10 @@ class MpxWebpackPlugin {
534
559
  }
535
560
  ], (err) => {
536
561
  if (err) return callback(err)
537
- const checkDynamicEntryInfo = () => {
538
- for (const packageName in mpx.dynamicEntryInfo) {
539
- const entryMap = mpx.dynamicEntryInfo[packageName]
540
- if (packageName !== 'main' && !entryMap.hasPage) {
541
- // 引用未注册分包的所有资源
542
- const resources = entryMap.entries.map(info => info.resource).join(',')
543
- compilation.errors.push(new Error(`资源${resources}通过分包异步声明为${packageName}分包, 但${packageName}分包未注册或不存在相关页面!`))
544
- }
545
- }
562
+ if (mpx.supportRequireAsync && mpx.mode !== 'tt') {
563
+ // 字节小程序异步分包中不能包含page,忽略该检查
564
+ checkDynamicEntryInfo(compilation)
546
565
  }
547
- checkDynamicEntryInfo()
548
566
  callback()
549
567
  })
550
568
  })
@@ -619,6 +637,8 @@ class MpxWebpackPlugin {
619
637
  if (!compilation.__mpx__) {
620
638
  // init mpx
621
639
  mpx = compilation.__mpx__ = {
640
+ // 用于使用webpack-virtual-modules功能,目前仅输出web时下支持使用
641
+ __vfs,
622
642
  // app信息,便于获取appName
623
643
  appInfo: {},
624
644
  // pages全局记录,无需区分主包分包
@@ -688,7 +708,7 @@ class MpxWebpackPlugin {
688
708
  useRelativePath: this.options.useRelativePath,
689
709
  removedChunks: [],
690
710
  forceProxyEventRules: this.options.forceProxyEventRules,
691
- supportRequireAsync: this.options.mode === 'wx' || this.options.mode === 'ali' || isWeb(this.options.mode),
711
+ supportRequireAsync: this.options.mode === 'wx' || this.options.mode === 'ali' || this.options.mode === 'tt' || isWeb(this.options.mode),
692
712
  partialCompileRules: this.options.partialCompileRules,
693
713
  collectDynamicEntryInfo: ({ resource, packageName, filename, entryType, hasAsync }) => {
694
714
  const curInfo = mpx.dynamicEntryInfo[packageName] = mpx.dynamicEntryInfo[packageName] || {
@@ -56,7 +56,6 @@ module.exports = function createJSONHelper ({ loaderContext, emitWarning, custom
56
56
  if (queryObj.root) {
57
57
  // 删除root query
58
58
  resource = addQuery(resource, {}, false, ['root'])
59
- // 目前只有微信支持分包异步化
60
59
  if (supportRequireAsync) {
61
60
  tarRoot = queryObj.root
62
61
  extraOptions.isAsync = true
@@ -2545,18 +2545,18 @@ function processElement (el, root, options, meta) {
2545
2545
 
2546
2546
  processIf(el)
2547
2547
  processFor(el)
2548
- processRef(el, options, meta)
2549
- if (runtimeCompile) {
2550
- processClassDynamic(el, meta)
2551
- processStyleDynamic(el, meta)
2552
- } else {
2553
- processClass(el, meta)
2554
- processStyle(el, meta)
2555
- }
2556
- processEvent(el, options)
2557
2548
 
2558
2549
  if (!pass) {
2550
+ processRef(el, options, meta)
2551
+ if (runtimeCompile) {
2552
+ processClassDynamic(el, meta)
2553
+ processStyleDynamic(el, meta)
2554
+ } else {
2555
+ processClass(el, meta)
2556
+ processStyle(el, meta)
2557
+ }
2559
2558
  processShow(el, options, root)
2559
+ processEvent(el, options)
2560
2560
  processComponentIs(el, options)
2561
2561
  }
2562
2562
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.9.50",
3
+ "version": "2.9.55",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"
@@ -57,7 +57,8 @@
57
57
  "postcss-selector-parser": "^6.0.8",
58
58
  "postcss-value-parser": "^4.0.2",
59
59
  "semver": "^7.5.4",
60
- "source-list-map": "^2.0.0"
60
+ "source-list-map": "^2.0.0",
61
+ "webpack-virtual-modules": "^0.6.0"
61
62
  },
62
63
  "peerDependencies": {
63
64
  "webpack": "^5.75.0"
@@ -85,5 +86,5 @@
85
86
  "engines": {
86
87
  "node": ">=14.14.0"
87
88
  },
88
- "gitHead": "d8b89e0ba1f29a16244b247f6c7a8d8197e0d732"
89
+ "gitHead": "8e2e9dace226d48a91ff2a6dc2175c0a3be11d55"
89
90
  }