@mpxjs/webpack-plugin 2.9.48 → 2.9.54

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) {
@@ -619,6 +634,8 @@ class MpxWebpackPlugin {
619
634
  if (!compilation.__mpx__) {
620
635
  // init mpx
621
636
  mpx = compilation.__mpx__ = {
637
+ // 用于使用webpack-virtual-modules功能,目前仅输出web时下支持使用
638
+ __vfs,
622
639
  // app信息,便于获取appName
623
640
  appInfo: {},
624
641
  // pages全局记录,无需区分主包分包
@@ -688,7 +705,7 @@ class MpxWebpackPlugin {
688
705
  useRelativePath: this.options.useRelativePath,
689
706
  removedChunks: [],
690
707
  forceProxyEventRules: this.options.forceProxyEventRules,
691
- supportRequireAsync: this.options.mode === 'wx' || this.options.mode === 'ali' || isWeb(this.options.mode),
708
+ supportRequireAsync: this.options.mode === 'wx' || this.options.mode === 'ali' || this.options.mode === 'tt' || isWeb(this.options.mode),
692
709
  partialCompileRules: this.options.partialCompileRules,
693
710
  collectDynamicEntryInfo: ({ resource, packageName, filename, entryType, hasAsync }) => {
694
711
  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
@@ -19,7 +19,7 @@ module.exports = function getSpec ({ warn, error }) {
19
19
  if (name.startsWith('data-')) {
20
20
  return {
21
21
  name: ':' + name,
22
- value: `JSON.stringify(${parsed.result})`
22
+ value: `__ensureString(${parsed.result})`
23
23
  }
24
24
  } else if (parsed.hasBinding) {
25
25
  return {
@@ -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.48",
3
+ "version": "2.9.54",
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": "f1bd7c32ec48c4401ab1bf68247bc68834ca932b"
89
+ "gitHead": "973791aa35b1846bb96efe421f7ce266b2531455"
89
90
  }