@mpxjs/webpack-plugin 2.8.35 → 2.9.0-beta.0

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
@@ -432,9 +432,9 @@ class MpxWebpackPlugin {
432
432
  mpx.staticResourcesMap[packageRoot] = mpx.staticResourcesMap[packageRoot] || {}
433
433
  mpx.subpackageModulesMap[packageRoot] = mpx.subpackageModulesMap[packageRoot] || {}
434
434
  async.each(deps, (dep, callback) => {
435
- dep.addEntry(compilation, (err, { resultPath }) => {
435
+ dep.addEntry(compilation, (err, result) => {
436
436
  if (err) return callback(err)
437
- dep.resultPath = mpx.replacePathMap[dep.key] = resultPath
437
+ dep.resultPath = mpx.replacePathMap[dep.key] = result.resultPath
438
438
  callback()
439
439
  })
440
440
  }, callback)
@@ -453,7 +453,8 @@ class MpxWebpackPlugin {
453
453
  name: 'MpxWebpackPlugin',
454
454
  stage: -1000
455
455
  }, (compilation, callback) => {
456
- processSubpackagesEntriesMap(compilation, () => {
456
+ processSubpackagesEntriesMap(compilation, (err) => {
457
+ if (err) return callback(err)
457
458
  const checkRegisterPack = () => {
458
459
  for (const packRoot in mpx.dynamicEntryInfo) {
459
460
  const entryMap = mpx.dynamicEntryInfo[packRoot]
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)
@@ -161,23 +160,33 @@ module.exports = function (content) {
161
160
  // 处理mode为web时输出vue格式文件
162
161
  if (mode === 'web') {
163
162
  if (ctorType === 'app' && !queryObj.isApp) {
164
- const request = addQuery(this.resource, { isApp: true })
165
- const el = mpx.webConfig.el || '#app'
166
- output += `
167
- import App from ${stringifyRequest(request)}
168
- import Vue from 'vue'
169
- new Vue({
170
- el: '${el}',
171
- render: function(h){
172
- return h(App)
173
- }
174
- })\n
175
- `
176
- // 直接结束loader进入parse
177
- this.loaderIndex = -1
178
- return callback(null, output)
163
+ return async.waterfall([
164
+ (callback) => {
165
+ processJSON(parts.json, { loaderContext, pagesMap, componentsMap }, callback)
166
+ },
167
+ (jsonRes, callback) => {
168
+ processMainScript(parts.script, {
169
+ loaderContext,
170
+ ctorType,
171
+ srcMode,
172
+ moduleId,
173
+ isProduction,
174
+ jsonConfig: jsonRes.jsonObj,
175
+ outputPath: queryObj.outputPath || '',
176
+ localComponentsMap: jsonRes.localComponentsMap,
177
+ tabBar: jsonRes.jsonObj.tabBar,
178
+ tabBarMap: jsonRes.tabBarMap,
179
+ tabBarStr: jsonRes.tabBarStr,
180
+ localPagesMap: jsonRes.localPagesMap,
181
+ resource: this.resource
182
+ }, callback)
183
+ }
184
+ ], (err, scriptRes) => {
185
+ if (err) return callback(err)
186
+ this.loaderIndex = -1
187
+ return callback(null, scriptRes.output)
188
+ })
179
189
  }
180
-
181
190
  // 通过RecordVueContentDependency和vueContentCache确保子request不再重复生成vueContent
182
191
  const cacheContent = mpx.vueContentCache.get(filePath)
183
192
  if (cacheContent) return callback(null, cacheContent)
@@ -233,13 +242,10 @@ module.exports = function (content) {
233
242
  componentGenerics,
234
243
  jsonConfig: jsonRes.jsonObj,
235
244
  outputPath: queryObj.outputPath || '',
236
- tabBarMap: jsonRes.tabBarMap,
237
- tabBarStr: jsonRes.tabBarStr,
238
245
  builtInComponentsMap: templateRes.builtInComponentsMap,
239
246
  genericsInfo: templateRes.genericsInfo,
240
247
  wxsModuleMap: templateRes.wxsModuleMap,
241
- localComponentsMap: jsonRes.localComponentsMap,
242
- localPagesMap: jsonRes.localPagesMap
248
+ localComponentsMap: jsonRes.localComponentsMap
243
249
  }, callback)
244
250
  }
245
251
  ], (err, scriptRes) => {
@@ -249,7 +255,6 @@ module.exports = function (content) {
249
255
  callback(null, output)
250
256
  })
251
257
  }
252
-
253
258
  const moduleGraph = this._compilation.moduleGraph
254
259
 
255
260
  const issuer = moduleGraph.getIssuer(this._module)
@@ -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, { extendEvent } from './getInnerListeners'
3
+ import { isBrowser } from '../../env'
3
4
 
4
5
  export default {
5
6
  name: 'mpx-image',
@@ -21,25 +22,27 @@
21
22
  }
22
23
  },
23
24
  beforeCreate () {
24
- this.image = new Image()
25
- this.image.onload = (e) => {
26
- extendEvent(e, {
27
- detail: {
28
- width: this.image.width,
29
- height: this.image.height
30
- }
31
- })
25
+ if (isBrowser) {
26
+ this.image = new Image()
27
+ this.image.onload = (e) => {
28
+ extendEvent(e, {
29
+ detail: {
30
+ width: this.image.width,
31
+ height: this.image.height
32
+ }
33
+ })
32
34
 
33
- this.$emit('load', e)
34
- }
35
- this.image.onerror = (e) => {
36
- this.$emit('error', e)
35
+ this.$emit('load', e)
36
+ }
37
+ this.image.onerror = (e) => {
38
+ this.$emit('error', e)
39
+ }
37
40
  }
38
41
  },
39
42
  watch: {
40
43
  src: {
41
44
  handler (src) {
42
- if (src) this.image.src = src
45
+ if (src && this.image) this.image.src = src
43
46
  },
44
47
  immediate: true
45
48
  }
@@ -34,27 +34,32 @@
34
34
  }
35
35
  },
36
36
  render (createElement) {
37
- let text = ''
38
37
  let classNames = ['mpx-text']
39
38
  let decode = false
40
39
  const slots = this.$slots.default || []
40
+ const newSlots = []
41
41
  slots.forEach((item) => {
42
42
  if (item.text) {
43
- // item.text = encodeText(item.text)
44
- text += item.text
43
+ switch (this.space) {
44
+ case 'ensp':
45
+ case 'emsp':
46
+ case 'nbsp':
47
+ decode = true
48
+ item.text = item.text.replace(/ /g, `&${this.space};`)
49
+ break
50
+ }
51
+ newSlots.push(createElement('span', {
52
+ domProps: {
53
+ innerHTML: item.text
54
+ }
55
+ }))
56
+ } else {
57
+ newSlots.push(item)
45
58
  }
46
59
  })
47
60
  if (this.selectable) {
48
61
  classNames.push('selectable')
49
62
  }
50
- switch (this.space) {
51
- case 'ensp':
52
- case 'emsp':
53
- case 'nbsp':
54
- decode = true
55
- text = text.replace(/ /g, `&${this.space};`)
56
- break
57
- }
58
63
  if (this.decode) {
59
64
  decode = true
60
65
  }
@@ -62,12 +67,7 @@
62
67
  class: classNames,
63
68
  on: getInnerListeners(this)
64
69
  }
65
- if (decode) {
66
- data.domProps = {
67
- innerHTML: text
68
- }
69
- }
70
- return createElement('span', data, slots)
70
+ return createElement('span', data, decode ? newSlots : slots)
71
71
  }
72
72
  }
73
73
  </script>
@@ -3,7 +3,7 @@
3
3
  </template>
4
4
 
5
5
  <script>
6
- import getInnerListeners, { getCustomEvent } from './getInnerListeners'
6
+ import { getCustomEvent } from './getInnerListeners'
7
7
  import { redirectTo, navigateTo, navigateBack, reLaunch, switchTab} from '@mpxjs/api-proxy/src/web/api/index'
8
8
 
9
9
  const eventLoad = 'load'
@@ -43,7 +43,7 @@
43
43
  return domain
44
44
  }
45
45
  },
46
- created () {
46
+ mounted () {
47
47
  setTimeout(() => {
48
48
  if (!this.Loaded) {
49
49
  const loadData = {
@@ -52,8 +52,6 @@
52
52
  this.$emit(eventError, getCustomEvent(eventError, loadData))
53
53
  }
54
54
  }, 1000)
55
- },
56
- mounted () {
57
55
  this.mpxIframe = this.$refs.mpxIframe
58
56
  this.mpxIframe.addEventListener('load', (event) => {
59
57
  event.currentTarget.contentWindow.postMessage(this.mainDomain, '*')