@mpxjs/webpack-plugin 2.7.15 → 2.7.16

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
@@ -33,6 +33,7 @@ const DynamicEntryDependency = require('./dependencies/DynamicEntryDependency')
33
33
  const FlagPluginDependency = require('./dependencies/FlagPluginDependency')
34
34
  const RemoveEntryDependency = require('./dependencies/RemoveEntryDependency')
35
35
  const SplitChunksPlugin = require('webpack/lib/optimize/SplitChunksPlugin')
36
+ const PartialCompilePlugin = require('./partial-compile/index')
36
37
  const fixRelative = require('./utils/fix-relative')
37
38
  const parseRequest = require('./utils/parse-request')
38
39
  const { matchCondition } = require('./utils/match-condition')
@@ -159,6 +160,7 @@ class MpxWebpackPlugin {
159
160
  cssLangs: ['css', 'less', 'stylus', 'scss', 'sass']
160
161
  }, options.nativeConfig)
161
162
  options.webConfig = options.webConfig || {}
163
+ options.partialCompile = options.mode !== 'web' && options.partialCompile
162
164
  this.options = options
163
165
  // Hack for buildDependencies
164
166
  const rawResolveBuildDependencies = FileSystemInfo.prototype.resolveBuildDependencies
@@ -366,6 +368,10 @@ class MpxWebpackPlugin {
366
368
 
367
369
  let mpx
368
370
 
371
+ if (this.options.partialCompile) {
372
+ new PartialCompilePlugin(this.options.partialCompile).apply(compiler)
373
+ }
374
+
369
375
  const getPackageCacheGroup = packageName => {
370
376
  if (packageName === 'main') {
371
377
  return {
@@ -97,6 +97,8 @@ module.exports = function createJSONHelper ({ loaderContext, emitWarning, custom
97
97
  if (resolveMode === 'native') {
98
98
  page = urlToRequest(page)
99
99
  }
100
+ // 增加 page 标识
101
+ page = addQuery(page, { isPage: true })
100
102
  resolve(context, page, loaderContext, (err, resource) => {
101
103
  if (err) return callback(err)
102
104
  const { resourcePath, queryObj: { isFirst } } = parseRequest(resource)
@@ -571,10 +571,14 @@ module.exports = function (content) {
571
571
  delete json.subPackages
572
572
  json.pages = localPages
573
573
  for (let root in subPackagesCfg) {
574
- if (!json.subPackages) {
575
- json.subPackages = []
574
+ const subPackageCfg = subPackagesCfg[root]
575
+ // 分包不存在 pages,输出 subPackages 字段会报错
576
+ if (subPackageCfg.pages.length) {
577
+ if (!json.subPackages) {
578
+ json.subPackages = []
579
+ }
580
+ json.subPackages.push(subPackageCfg)
576
581
  }
577
- json.subPackages.push(subPackagesCfg[root])
578
582
  }
579
583
  const processOutput = (output) => {
580
584
  output = processDynamicEntry(output)
@@ -0,0 +1,35 @@
1
+ const { matchCondition } = require('../utils/match-condition')
2
+ const { parseQuery } = require('loader-utils')
3
+
4
+ class MpxPartialCompilePlugin {
5
+ constructor (condition) {
6
+ this.condition = condition
7
+ }
8
+
9
+ isResolvingPage (obj) {
10
+ // valid query should start with '?'
11
+ const query = obj.query || '?'
12
+ return parseQuery(query).isPage
13
+ }
14
+
15
+ apply (compiler) {
16
+ compiler.resolverFactory.hooks.resolver.intercept({
17
+ factory: (type, hook) => {
18
+ hook.tap('MpxPartialCompilePlugin', (resolver) => {
19
+ resolver.hooks.result.tapAsync({
20
+ name: 'MpxPartialCompilePlugin',
21
+ stage: -100
22
+ }, (obj, resolverContext, callback) => {
23
+ if (this.isResolvingPage(obj) && !matchCondition(obj.path, this.condition)) {
24
+ obj.path = false
25
+ }
26
+ callback(null, obj)
27
+ })
28
+ })
29
+ return hook
30
+ }
31
+ })
32
+ }
33
+ }
34
+
35
+ module.exports = MpxPartialCompilePlugin
@@ -1822,7 +1822,8 @@ function processAliAddComponentRootView (el, options) {
1822
1822
  { condition: /^(on|catch)TouchCancel$/, action: 'clone' },
1823
1823
  { condition: /^(on|catch)LongTap$/, action: 'clone' },
1824
1824
  { condition: /^data-/, action: 'clone' },
1825
- { condition: 'style', action: 'move' }
1825
+ { condition: /^style$/, action: 'move' },
1826
+ { condition: /^slot$/, action: 'move' }
1826
1827
  ]
1827
1828
  const processAppendAttrsRules = [
1828
1829
  { name: 'class', value: `${MPX_ROOT_VIEW} host-${options.moduleId}` }
@@ -1835,13 +1836,8 @@ function processAliAddComponentRootView (el, options) {
1835
1836
  }
1836
1837
 
1837
1838
  function processMove (attr) {
1838
- let movedAttr = getAndRemoveAttr(el, attr.name)
1839
- if (movedAttr.has) {
1840
- newElAttrs.push({
1841
- name: attr,
1842
- value: movedAttr.val
1843
- })
1844
- }
1839
+ getAndRemoveAttr(el, attr.name)
1840
+ newElAttrs.push(attr)
1845
1841
  }
1846
1842
 
1847
1843
  function processAppendRules (el) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.7.15",
3
+ "version": "2.7.16",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"
@@ -80,5 +80,5 @@
80
80
  "engines": {
81
81
  "node": ">=14.14.0"
82
82
  },
83
- "gitHead": "bf6b0d9938fecb4faafa2557c2c2caad1ea98535"
83
+ "gitHead": "7a2b5ae385cbd035172ec11bc0bfba84eff10243"
84
84
  }