@mpxjs/webpack-plugin 2.8.40-beta.0 → 2.8.40

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.
@@ -35,15 +35,6 @@ class ResolveDependency extends NullDependency {
35
35
  return pagesMap[resourcePath] || currentComponentsMap[resourcePath] || mainComponentsMap[resourcePath] || currentStaticResourcesMap[resourcePath] || mainStaticResourcesMap[resourcePath] || ''
36
36
  }
37
37
 
38
- isPartialCompileFilteredPage (resource) {
39
- const { compilation } = this
40
- if (!compilation) return ''
41
- const mpx = compilation.__mpx__
42
- const { partialCompileFilteredPagesMap } = mpx
43
- const { resourcePath } = parseRequest(resource)
44
- return partialCompileFilteredPagesMap[resourcePath]
45
- }
46
-
47
38
  // resolved可能会动态变更,需用此更新hash
48
39
  updateHash (hash, context) {
49
40
  this.resolved = this.getResolved()
@@ -51,9 +42,7 @@ class ResolveDependency extends NullDependency {
51
42
  if (this.resolved) {
52
43
  hash.update(this.resolved)
53
44
  } else {
54
- if (!this.isPartialCompileFilteredPage(resource)) {
55
- compilation.errors.push(new Error(`Path ${resource} is not a page/component/static resource, which is resolved from ${issuerResource}!`))
56
- }
45
+ compilation.errors.push(new Error(`Path ${resource} is not a page/component/static resource, which is resolved from ${issuerResource}!`))
57
46
  }
58
47
  super.updateHash(hash, context)
59
48
  }
package/lib/index.js CHANGED
@@ -38,6 +38,7 @@ const FlagPluginDependency = require('./dependencies/FlagPluginDependency')
38
38
  const RemoveEntryDependency = require('./dependencies/RemoveEntryDependency')
39
39
  const RecordVueContentDependency = require('./dependencies/RecordVueContentDependency')
40
40
  const SplitChunksPlugin = require('webpack/lib/optimize/SplitChunksPlugin')
41
+ const PartialCompilePlugin = require('./partial-compile/index')
41
42
  const fixRelative = require('./utils/fix-relative')
42
43
  const parseRequest = require('./utils/parse-request')
43
44
  const { matchCondition } = require('./utils/match-condition')
@@ -54,7 +55,6 @@ const jsonThemeCompilerPath = normalize.lib('json-compiler/theme')
54
55
  const jsonPluginCompilerPath = normalize.lib('json-compiler/plugin')
55
56
  const extractorPath = normalize.lib('extractor')
56
57
  const async = require('async')
57
- const { parseQuery } = require('loader-utils')
58
58
  const stringifyLoadersAndResource = require('./utils/stringify-loaders-resource')
59
59
  const emitFile = require('./utils/emit-file')
60
60
  const { MPX_PROCESSED_FLAG, MPX_DISABLE_EXTRACTOR_CACHE } = require('./utils/const')
@@ -381,29 +381,7 @@ class MpxWebpackPlugin {
381
381
  let mpx
382
382
 
383
383
  if (this.options.partialCompile) {
384
- function isResolvingPage (obj) {
385
- // valid query should start with '?'
386
- const query = obj.query || '?'
387
- return parseQuery(query).isPage
388
- }
389
- // new PartialCompilePlugin(this.options.partialCompile).apply(compiler)
390
- compiler.resolverFactory.hooks.resolver.intercept({
391
- factory: (type, hook) => {
392
- hook.tap('MpxPartialCompilePlugin', (resolver) => {
393
- resolver.hooks.result.tapAsync({
394
- name: 'MpxPartialCompilePlugin',
395
- stage: -100
396
- }, (obj, resolverContext, callback) => {
397
- if (isResolvingPage(obj) && !matchCondition(obj.path, this.options.partialCompile)) {
398
- if (mpx) mpx.partialCompileFilteredPagesMap[obj.path] = true
399
- obj.path = false
400
- }
401
- callback(null, obj)
402
- })
403
- })
404
- return hook
405
- }
406
- })
384
+ new PartialCompilePlugin(this.options.partialCompile).apply(compiler)
407
385
  }
408
386
 
409
387
  const getPackageCacheGroup = packageName => {
@@ -617,7 +595,6 @@ class MpxWebpackPlugin {
617
595
  removedChunks: [],
618
596
  forceProxyEventRules: this.options.forceProxyEventRules,
619
597
  enableRequireAsync: this.options.mode === 'wx' || (this.options.mode === 'ali' && this.options.enableAliRequireAsync),
620
- partialCompileFilteredPagesMap: {},
621
598
  pathHash: (resourcePath) => {
622
599
  if (this.options.pathHashMode === 'relative' && this.options.projectRoot) {
623
600
  return hash(path.relative(this.options.projectRoot, resourcePath))
@@ -6,7 +6,6 @@ const parseRequest = require('../utils/parse-request')
6
6
  const addQuery = require('../utils/add-query')
7
7
  const loaderUtils = require('loader-utils')
8
8
  const resolve = require('../utils/resolve')
9
- const { RESOLVE_IGNORED_ERR } = require('../utils/const')
10
9
 
11
10
  module.exports = function createJSONHelper ({ loaderContext, emitWarning, customGetDynamicEntry }) {
12
11
  const mpx = loaderContext.getMpx()
@@ -102,15 +101,7 @@ module.exports = function createJSONHelper ({ loaderContext, emitWarning, custom
102
101
  // 增加 page 标识
103
102
  page = addQuery(page, { isPage: true })
104
103
  resolve(context, page, loaderContext, (err, resource) => {
105
- if (err) {
106
- if (err === RESOLVE_IGNORED_ERR && tarRoot) {
107
- const defaultPage = require.resolve('./default-page.mpx') + `?resourcePath=${context}/${tarRoot}/pages/index.mpx`
108
- resource = defaultPage
109
- aliasPath = ''
110
- } else {
111
- return callback(err)
112
- }
113
- }
104
+ if (err) return callback(err)
114
105
  const { resourcePath, queryObj: { isFirst } } = parseRequest(resource)
115
106
  const ext = path.extname(resourcePath)
116
107
  let outputPath
@@ -577,10 +577,12 @@ module.exports = function (content) {
577
577
  for (const root in subPackagesCfg) {
578
578
  const subPackageCfg = subPackagesCfg[root]
579
579
  // 分包不存在 pages,输出 subPackages 字段会报错
580
- if (!json.subPackages) {
581
- json.subPackages = []
580
+ if (subPackageCfg.pages.length) {
581
+ if (!json.subPackages) {
582
+ json.subPackages = []
583
+ }
584
+ json.subPackages.push(subPackageCfg)
582
585
  }
583
- json.subPackages.push(subPackageCfg)
584
586
  }
585
587
  const processOutput = (output) => {
586
588
  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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.8.40-beta.0",
3
+ "version": "2.8.40",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"
@@ -82,5 +82,5 @@
82
82
  "engines": {
83
83
  "node": ">=14.14.0"
84
84
  },
85
- "gitHead": "03d5373a8526f23e00f05917aaf84f6fbb7ef98f"
85
+ "gitHead": "46a9b88c11f1ca2f0cfbc414e668b2f618ee6806"
86
86
  }
@@ -1,3 +0,0 @@
1
- <template>
2
- <view>局部构建兜底页面</view>
3
- </template>