@mpxjs/webpack-plugin 2.8.63 → 2.8.64-bridgetest

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.
@@ -28,23 +28,10 @@ class DynamicEntryDependency extends NullDependency {
28
28
  return toPosix([request, entryType, outputPath, packageRoot, relativePath, context, ...range].join('|'))
29
29
  }
30
30
 
31
- collectDynamicRequest (mpx) {
32
- if (!this.packageRoot) return
33
- const curValue = mpx.dynamicEntryInfo[this.packageRoot] = mpx.dynamicEntryInfo[this.packageRoot] || {
34
- hasPage: false,
35
- entries: []
36
- }
37
- if (this.entryType === 'page') {
38
- curValue.hasPage = true
39
- } else {
40
- curValue.entries.push(this.request)
41
- }
42
- }
43
-
44
31
  addEntry (compilation, callback) {
45
32
  const mpx = compilation.__mpx__
46
33
  let { request, entryType, outputPath, relativePath, context, originEntryNode, publicPath, resolver } = this
47
- this.collectDynamicRequest(mpx)
34
+
48
35
  async.waterfall([
49
36
  (callback) => {
50
37
  if (context && resolver) {
@@ -56,12 +43,13 @@ class DynamicEntryDependency extends NullDependency {
56
43
  }
57
44
  },
58
45
  (resource, callback) => {
46
+ const { resourcePath } = parseRequest(resource)
47
+
59
48
  if (!outputPath) {
60
- const { resourcePath } = parseRequest(resource)
61
49
  outputPath = mpx.getOutputPath(resourcePath, entryType)
62
50
  }
63
51
 
64
- const { packageRoot, outputPath: filename, alreadyOutputted } = mpx.getPackageInfo({
52
+ const { packageName, packageRoot, outputPath: filename, alreadyOutputted } = mpx.getPackageInfo({
65
53
  resource,
66
54
  outputPath,
67
55
  resourceType: entryType,
@@ -116,6 +104,12 @@ class DynamicEntryDependency extends NullDependency {
116
104
  .catch(err => callback(err))
117
105
 
118
106
  mpx.addEntryPromiseMap.set(key, addEntryPromise)
107
+ mpx.collectDynamicEntryInfo({
108
+ resource,
109
+ packageName,
110
+ filename,
111
+ entryType
112
+ })
119
113
  }
120
114
  }
121
115
  ], callback)
package/lib/index.js CHANGED
@@ -113,7 +113,6 @@ class MpxWebpackPlugin {
113
113
  constructor (options = {}) {
114
114
  options.mode = options.mode || 'wx'
115
115
  options.env = options.env || ''
116
-
117
116
  options.srcMode = options.srcMode || options.mode
118
117
  if (options.mode !== options.srcMode && options.srcMode !== 'wx') {
119
118
  errors.push('MpxWebpackPlugin supports srcMode to be "wx" only temporarily!')
@@ -494,17 +493,17 @@ class MpxWebpackPlugin {
494
493
  }, (compilation, callback) => {
495
494
  processSubpackagesEntriesMap(compilation, (err) => {
496
495
  if (err) return callback(err)
497
- const checkRegisterPack = () => {
498
- for (const packRoot in mpx.dynamicEntryInfo) {
499
- const entryMap = mpx.dynamicEntryInfo[packRoot]
500
- if (!entryMap.hasPage) {
496
+ const checkDynamicEntryInfo = () => {
497
+ for (const packageName in mpx.dynamicEntryInfo) {
498
+ const entryMap = mpx.dynamicEntryInfo[packageName]
499
+ if (packageName !== 'main' && !entryMap.hasPage) {
501
500
  // 引用未注册分包的所有资源
502
- const strRequest = entryMap.entries.join(',')
503
- compilation.errors.push(new Error(`资源${strRequest}目标是打入${packRoot}分包, 但是app.json中并未声明${packRoot}分包`))
501
+ const resources = entryMap.entries.map(info => info.resource).join(',')
502
+ compilation.errors.push(new Error(`资源${resources}通过分包异步声明为${packageName}分包, 但${packageName}分包未注册或不存在相关页面!`))
504
503
  }
505
504
  }
506
505
  }
507
- checkRegisterPack()
506
+ checkDynamicEntryInfo()
508
507
  callback()
509
508
  })
510
509
  })
@@ -564,8 +563,8 @@ class MpxWebpackPlugin {
564
563
  })
565
564
 
566
565
  compiler.hooks.thisCompilation.tap('MpxWebpackPlugin', (compilation, { normalModuleFactory }) => {
567
- compilation.warnings = compilation.warnings.concat(warnings)
568
- compilation.errors = compilation.errors.concat(errors)
566
+ compilation.warnings.push(...warnings)
567
+ compilation.errors.push(...errors)
569
568
  const moduleGraph = compilation.moduleGraph
570
569
 
571
570
  if (!compilation.__mpx__) {
@@ -594,7 +593,7 @@ class MpxWebpackPlugin {
594
593
  subpackagesEntriesMap: {},
595
594
  replacePathMap: {},
596
595
  exportModules: new Set(),
597
- // 动态记录注册的分包与注册页面映射
596
+ // 记录动态添加入口的分包信息
598
597
  dynamicEntryInfo: {},
599
598
  // 记录entryModule与entryNode的对应关系,用于体积分析
600
599
  entryNodeModulesMap: new Map(),
@@ -638,6 +637,18 @@ class MpxWebpackPlugin {
638
637
  forceProxyEventRules: this.options.forceProxyEventRules,
639
638
  enableRequireAsync: this.options.mode === 'wx' || (this.options.mode === 'ali' && this.options.enableAliRequireAsync),
640
639
  partialCompile: this.options.partialCompile,
640
+ collectDynamicEntryInfo: ({ resource, packageName, filename, entryType }) => {
641
+ const curInfo = mpx.dynamicEntryInfo[packageName] = mpx.dynamicEntryInfo[packageName] || {
642
+ hasPage: false,
643
+ entries: []
644
+ }
645
+ if (entryType === 'page') curInfo.hasPage = true
646
+ curInfo.entries.push({
647
+ entryType,
648
+ resource,
649
+ filename
650
+ })
651
+ },
641
652
  asyncSubpackageRules: this.options.asyncSubpackageRules,
642
653
  optimizeRenderRules: this.options.optimizeRenderRules,
643
654
  pathHash: (resourcePath) => {
@@ -646,7 +657,7 @@ class MpxWebpackPlugin {
646
657
  }
647
658
  return hash(resourcePath)
648
659
  },
649
- addEntry (request, name, callback) {
660
+ addEntry: (request, name, callback) => {
650
661
  const dep = EntryPlugin.createDependency(request, { name })
651
662
  compilation.addEntry(compiler.context, dep, { name }, callback)
652
663
  return dep
@@ -814,10 +825,14 @@ class MpxWebpackPlugin {
814
825
  const rawProcessModuleDependencies = compilation.processModuleDependencies
815
826
  compilation.processModuleDependencies = (module, callback) => {
816
827
  const presentationalDependencies = module.presentationalDependencies || []
828
+ const errors = []
817
829
  async.forEach(presentationalDependencies.filter((dep) => dep.mpxAction), (dep, callback) => {
818
- dep.mpxAction(module, compilation, callback)
819
- }, (err) => {
820
- if (err) compilation.errors.push(err)
830
+ dep.mpxAction(module, compilation, (err) => {
831
+ if (err) errors.push(err)
832
+ callback()
833
+ })
834
+ }, () => {
835
+ compilation.errors.push(...errors)
821
836
  rawProcessModuleDependencies.call(compilation, module, callback)
822
837
  })
823
838
  }
@@ -903,16 +918,17 @@ class MpxWebpackPlugin {
903
918
  }
904
919
 
905
920
  // hack process https://github.com/webpack/webpack/issues/16045
906
- const _handleModuleBuildAndDependenciesRaw = compilation._handleModuleBuildAndDependencies
907
-
908
- compilation._handleModuleBuildAndDependencies = (originModule, module, recursive, callback) => {
909
- const rawCallback = callback
910
- callback = (err) => {
911
- if (err) return rawCallback(err)
912
- return rawCallback(null, module)
913
- }
914
- return _handleModuleBuildAndDependenciesRaw.call(compilation, originModule, module, recursive, callback)
915
- }
921
+ // no need anymore
922
+ // const _handleModuleBuildAndDependenciesRaw = compilation._handleModuleBuildAndDependencies
923
+ //
924
+ // compilation._handleModuleBuildAndDependencies = (originModule, module, recursive, callback) => {
925
+ // const rawCallback = callback
926
+ // callback = (err) => {
927
+ // if (err) return rawCallback(err)
928
+ // return rawCallback(null, module)
929
+ // }
930
+ // return _handleModuleBuildAndDependenciesRaw.call(compilation, originModule, module, recursive, callback)
931
+ // }
916
932
 
917
933
  const rawEmitAsset = compilation.emitAsset
918
934
 
package/lib/loader.js CHANGED
@@ -1,7 +1,6 @@
1
1
  const JSON5 = require('json5')
2
2
  const parseComponent = require('./parser')
3
3
  const createHelpers = require('./helpers')
4
- const loaderUtils = require('loader-utils')
5
4
  const parseRequest = require('./utils/parse-request')
6
5
  const { matchCondition } = require('./utils/match-condition')
7
6
  const addQuery = require('./utils/add-query')
@@ -20,6 +19,7 @@ const CommonJsVariableDependency = require('./dependencies/CommonJsVariableDepen
20
19
  const tsWatchRunLoaderFilter = require('./utils/ts-loader-watch-run-loader-filter')
21
20
  const { MPX_APP_MODULE_ID } = require('./utils/const')
22
21
  const path = require('path')
22
+ const processMainScript = require('./web/processMainScript')
23
23
  const getRulesRunner = require('./platform')
24
24
 
25
25
  module.exports = function (content) {
@@ -85,7 +85,6 @@ module.exports = function (content) {
85
85
  if (appName) this._module.addPresentationalDependency(new AppEntryDependency(resourcePath, appName))
86
86
  }
87
87
  const loaderContext = this
88
- const stringifyRequest = r => loaderUtils.stringifyRequest(loaderContext, r)
89
88
  const isProduction = this.minimize || process.env.NODE_ENV === 'production'
90
89
  const filePath = this.resourcePath
91
90
  const moduleId = ctorType === 'app' ? MPX_APP_MODULE_ID : 'm' + mpx.pathHash(filePath)
@@ -154,23 +153,33 @@ module.exports = function (content) {
154
153
  // 处理mode为web时输出vue格式文件
155
154
  if (mode === 'web') {
156
155
  if (ctorType === 'app' && !queryObj.isApp) {
157
- const request = addQuery(this.resource, { isApp: true })
158
- const el = mpx.webConfig.el || '#app'
159
- output += `
160
- import App from ${stringifyRequest(request)}
161
- import Vue from 'vue'
162
- new Vue({
163
- el: '${el}',
164
- render: function(h){
165
- return h(App)
166
- }
167
- })\n
168
- `
169
- // 直接结束loader进入parse
170
- this.loaderIndex = -1
171
- return callback(null, output)
156
+ return async.waterfall([
157
+ (callback) => {
158
+ processJSON(parts.json, { loaderContext, pagesMap, componentsMap }, callback)
159
+ },
160
+ (jsonRes, callback) => {
161
+ processMainScript(parts.script, {
162
+ loaderContext,
163
+ ctorType,
164
+ srcMode,
165
+ moduleId,
166
+ isProduction,
167
+ jsonConfig: jsonRes.jsonObj,
168
+ outputPath: queryObj.outputPath || '',
169
+ localComponentsMap: jsonRes.localComponentsMap,
170
+ tabBar: jsonRes.jsonObj.tabBar,
171
+ tabBarMap: jsonRes.tabBarMap,
172
+ tabBarStr: jsonRes.tabBarStr,
173
+ localPagesMap: jsonRes.localPagesMap,
174
+ resource: this.resource
175
+ }, callback)
176
+ }
177
+ ], (err, scriptRes) => {
178
+ if (err) return callback(err)
179
+ this.loaderIndex = -1
180
+ return callback(null, scriptRes.output)
181
+ })
172
182
  }
173
-
174
183
  // 通过RecordVueContentDependency和vueContentCache确保子request不再重复生成vueContent
175
184
  const cacheContent = mpx.vueContentCache.get(filePath)
176
185
  if (cacheContent) return callback(null, cacheContent)
@@ -226,13 +235,10 @@ module.exports = function (content) {
226
235
  componentGenerics,
227
236
  jsonConfig: jsonRes.jsonObj,
228
237
  outputPath: queryObj.outputPath || '',
229
- tabBarMap: jsonRes.tabBarMap,
230
- tabBarStr: jsonRes.tabBarStr,
231
238
  builtInComponentsMap: templateRes.builtInComponentsMap,
232
239
  genericsInfo: templateRes.genericsInfo,
233
240
  wxsModuleMap: templateRes.wxsModuleMap,
234
- localComponentsMap: jsonRes.localComponentsMap,
235
- localPagesMap: jsonRes.localPagesMap
241
+ localComponentsMap: jsonRes.localComponentsMap
236
242
  }, callback)
237
243
  }
238
244
  ], (err, scriptRes) => {
@@ -242,7 +248,6 @@ module.exports = function (content) {
242
248
  callback(null, output)
243
249
  })
244
250
  }
245
-
246
251
  const moduleGraph = this._compilation.moduleGraph
247
252
 
248
253
  const issuer = moduleGraph.getIssuer(this._module)
package/lib/parser.js CHANGED
@@ -2,7 +2,6 @@ const cache = require('lru-cache')(100)
2
2
  const hash = require('hash-sum')
3
3
  const compiler = require('./template-compiler/compiler')
4
4
  const SourceMapGenerator = require('source-map').SourceMapGenerator
5
-
6
5
  const splitRE = /\r?\n/g
7
6
  const emptyRE = /^(?:\/\/)?\s*$/
8
7
 
@@ -1,5 +1,4 @@
1
- const templateCompiler = require('../../../../template-compiler/compiler')
2
- const parseMustache = templateCompiler.parseMustache
1
+ const { parseMustache } = require('../../../../template-compiler/compiler')
3
2
  const normalize = require('../../../../utils/normalize')
4
3
  const TAG_NAME = 'component'
5
4
 
@@ -3,9 +3,7 @@ const JSON5 = require('json5')
3
3
  const getComponentConfigs = require('./component-config')
4
4
  const normalizeComponentRules = require('../normalize-component-rules')
5
5
  const isValidIdentifierStr = require('../../../utils/is-valid-identifier-str')
6
- const templateCompiler = require('../../../template-compiler/compiler')
7
- const parseMustache = templateCompiler.parseMustache
8
- const stringifyWithResolveComputed = templateCompiler.stringifyWithResolveComputed
6
+ const { parseMustacheWithContext, stringifyWithResolveComputed } = require('../../../template-compiler/compiler')
9
7
  const normalize = require('../../../utils/normalize')
10
8
 
11
9
  module.exports = function getSpec ({ warn, error }) {
@@ -17,10 +15,10 @@ module.exports = function getSpec ({ warn, error }) {
17
15
  postProps: [
18
16
  {
19
17
  web ({ name, value }) {
20
- const parsed = parseMustache(value)
18
+ const parsed = parseMustacheWithContext(value)
21
19
  if (parsed.hasBinding) {
22
20
  return {
23
- name: name === 'animation' ? 'v-' + name : ':' + name,
21
+ name: name === 'animation' ? 'v-animation' : ':' + name,
24
22
  value: parsed.result
25
23
  }
26
24
  }
@@ -34,7 +32,7 @@ module.exports = function getSpec ({ warn, error }) {
34
32
  test: 'wx:for',
35
33
  swan (obj, data) {
36
34
  const attrsMap = data.el.attrsMap
37
- const parsed = parseMustache(obj.value)
35
+ const parsed = parseMustacheWithContext(obj.value)
38
36
  let listName = parsed.result
39
37
  const el = data.el
40
38
 
@@ -48,7 +46,7 @@ module.exports = function getSpec ({ warn, error }) {
48
46
  }
49
47
 
50
48
  if (keyName) {
51
- const parsed = parseMustache(keyName)
49
+ const parsed = parseMustacheWithContext(keyName)
52
50
  if (parsed.hasBinding) {
53
51
  // keyStr = ` trackBy ${parsed.result.slice(1, -1)}`
54
52
  } else if (keyName === '*this') {
@@ -78,7 +76,7 @@ module.exports = function getSpec ({ warn, error }) {
78
76
  }
79
77
  },
80
78
  web ({ value }, { el }) {
81
- const parsed = parseMustache(value)
79
+ const parsed = parseMustacheWithContext(value)
82
80
  const attrsMap = el.attrsMap
83
81
  const itemName = attrsMap['wx:for-item'] || 'item'
84
82
  const indexName = attrsMap['wx:for-index'] || 'index'
@@ -190,9 +188,8 @@ module.exports = function getSpec ({ warn, error }) {
190
188
  }
191
189
  const styleBinding = []
192
190
  el.isStyleParsed = true
193
- // 不过滤的话每一个属性都要 parse
194
191
  el.attrsList.filter(item => this.test.test(item.name)).forEach((item) => {
195
- const parsed = parseMustache(item.value)
192
+ const parsed = parseMustacheWithContext(item.value)
196
193
  styleBinding.push(parsed.result)
197
194
  })
198
195
  return {
@@ -205,7 +202,7 @@ module.exports = function getSpec ({ warn, error }) {
205
202
  // 样式类名绑定
206
203
  test: /^wx:(class)$/,
207
204
  web ({ value }) {
208
- const parsed = parseMustache(value)
205
+ const parsed = parseMustacheWithContext(value)
209
206
  return {
210
207
  name: ':class',
211
208
  value: parsed.result
@@ -259,7 +256,7 @@ module.exports = function getSpec ({ warn, error }) {
259
256
  },
260
257
  web ({ name, value }) {
261
258
  let dir = this.test.exec(name)[1]
262
- const parsed = parseMustache(value)
259
+ const parsed = parseMustacheWithContext(value)
263
260
  if (dir === 'elif') {
264
261
  dir = 'else-if'
265
262
  }
@@ -359,7 +356,7 @@ module.exports = function getSpec ({ warn, error }) {
359
356
  }
360
357
  },
361
358
  web ({ name, value }, { eventRules, el, usingComponents }) {
362
- if (parseMustache(value).hasBinding) {
359
+ if (parseMustacheWithContext(value).hasBinding) {
363
360
  error('Web environment does not support mustache binding in event props!')
364
361
  return
365
362
  }
@@ -48,9 +48,17 @@ span {
48
48
  white-space: pre-line;
49
49
  }
50
50
 
51
- html, body, .app {
51
+ html, body, #app {
52
+ display: block;
53
+ width: 100%;
54
+ height: 100%;
55
+ }
56
+
57
+ page {
58
+ display: block;
52
59
  width: 100%;
53
60
  height: 100%;
61
+ background-color: #fff;
54
62
  }
55
63
 
56
64
  .pull-down-loading {
@@ -1,8 +1,6 @@
1
1
  import { isEmptyObject } from '../../utils'
2
2
  import { isBrowser } from '../../env'
3
3
 
4
- const isTouchDevice = isBrowser ? document && ('ontouchstart' in document.documentElement) : true
5
-
6
4
  function processModel (listeners, context) {
7
5
  // 该函数只有wx:model的情况下才调用,而且默认e.detail.value有值
8
6
  // 该函数必须在产生merge前执行
@@ -49,6 +47,7 @@ function mergeListeners (listeners, otherListeners, options = {}) {
49
47
  function processTap (listeners, context) {
50
48
  const listenerMap = {}
51
49
  const tapEvents = ['tap', 'longpress', 'longtap']
50
+ const isTouchDevice = isBrowser ? document && ('ontouchstart' in document.documentElement) : true
52
51
  tapEvents.forEach((eventName) => {
53
52
  if (listeners[eventName]) {
54
53
  listenerMap[eventName] = true
@@ -1,5 +1,6 @@
1
1
  <script>
2
2
  import getInnerListeners, { getCustomEvent } from './getInnerListeners'
3
+ import { isBrowser } from '../../env'
3
4
 
4
5
  export default {
5
6
  name: 'mpx-image',
@@ -21,21 +22,23 @@
21
22
  }
22
23
  },
23
24
  beforeCreate () {
24
- this.image = new Image()
25
- this.image.onload = () => {
26
- this.$emit('load', getCustomEvent('load', {
27
- width: this.image.width,
28
- height: this.image.height
29
- }, this))
30
- }
31
- this.image.onerror = () => {
32
- this.$emit('error', getCustomEvent('error', {}, this))
25
+ if (isBrowser) {
26
+ this.image = new Image()
27
+ this.image.onload = () => {
28
+ this.$emit('load', getCustomEvent('load', {
29
+ width: this.image.width,
30
+ height: this.image.height
31
+ }, this))
32
+ }
33
+ this.image.onerror = () => {
34
+ this.$emit('error', getCustomEvent('error', {}, this))
35
+ }
33
36
  }
34
37
  },
35
38
  watch: {
36
39
  src: {
37
40
  handler (src) {
38
- if (src) this.image.src = src
41
+ if (src && this.image) this.image.src = src
39
42
  },
40
43
  immediate: true
41
44
  }