@mpxjs/webpack-plugin 2.8.47 → 2.8.49

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
@@ -170,6 +170,7 @@ class MpxWebpackPlugin {
170
170
  options.asyncSubpackageRules = options.asyncSubpackageRules || null
171
171
  options.retryRequireAsync = options.retryRequireAsync || false
172
172
  options.enableAliRequireAsync = options.enableAliRequireAsync || false
173
+ options.optimizeSize = options.optimizeSize || false
173
174
  this.options = options
174
175
  // Hack for buildDependencies
175
176
  const rawResolveBuildDependencies = FileSystemInfo.prototype.resolveBuildDependencies
@@ -294,6 +295,14 @@ class MpxWebpackPlugin {
294
295
  warnings.push(`webpack options: MpxWebpackPlugin accept options.output.filename to be ${outputFilename} only, custom options.output.filename will be ignored!`)
295
296
  }
296
297
  compiler.options.output.filename = compiler.options.output.chunkFilename = outputFilename
298
+ if (this.options.optimizeSize) {
299
+ compiler.options.optimization.chunkIds = 'total-size'
300
+ compiler.options.optimization.moduleIds = 'natural'
301
+ compiler.options.optimization.mangleExports = 'size'
302
+ compiler.options.output.globalObject = 'g'
303
+ // todo chunkLoadingGlobal不具备项目唯一性,在多构建产物混编时可能存在问题,尤其在支付宝使用全局对象传递的情况下
304
+ compiler.options.output.chunkLoadingGlobal = 'c'
305
+ }
297
306
  }
298
307
 
299
308
  if (!compiler.options.node || !compiler.options.node.global) {
@@ -387,6 +396,7 @@ class MpxWebpackPlugin {
387
396
  const query = parseQuery(obj.query || '?')
388
397
  return query.isPage && !query.type
389
398
  }
399
+
390
400
  // new PartialCompilePlugin(this.options.partialCompile).apply(compiler)
391
401
  compiler.resolverFactory.hooks.resolver.intercept({
392
402
  factory: (type, hook) => {
@@ -685,7 +695,15 @@ class MpxWebpackPlugin {
685
695
  mpx.extractedFilesCache.set(resource, file)
686
696
  return file
687
697
  },
688
- recordResourceMap: ({ resourcePath, resourceType, outputPath, packageRoot = '', recordOnly, warn, error }) => {
698
+ recordResourceMap: ({
699
+ resourcePath,
700
+ resourceType,
701
+ outputPath,
702
+ packageRoot = '',
703
+ recordOnly,
704
+ warn,
705
+ error
706
+ }) => {
689
707
  const packageName = packageRoot || 'main'
690
708
  const resourceMap = mpx[`${resourceType}sMap`] || mpx.otherResourcesMap
691
709
  const currentResourceMap = resourceMap.main ? resourceMap[packageName] = resourceMap[packageName] || {} : resourceMap
@@ -1297,6 +1315,8 @@ class MpxWebpackPlugin {
1297
1315
  chunkLoadingGlobal
1298
1316
  } = compilation.outputOptions
1299
1317
 
1318
+ const chunkLoadingGlobalStr = JSON.stringify(chunkLoadingGlobal)
1319
+
1300
1320
  function getTargetFile (file) {
1301
1321
  let targetFile = file
1302
1322
  const queryStringIdx = targetFile.indexOf('?')
@@ -1316,7 +1336,7 @@ class MpxWebpackPlugin {
1316
1336
 
1317
1337
  const originalSource = compilation.assets[chunkFile]
1318
1338
  const source = new ConcatSource()
1319
- source.add(`\nvar ${globalObject} = ${globalObject} || {};\n\n`)
1339
+ source.add(`\nvar ${globalObject} = {};\n`)
1320
1340
 
1321
1341
  relativeChunks.forEach((relativeChunk, index) => {
1322
1342
  const relativeChunkFile = relativeChunk.files.values().next().value
@@ -1333,16 +1353,16 @@ class MpxWebpackPlugin {
1333
1353
  if (compilation.options.entry[chunk.name]) {
1334
1354
  // 在rootChunk中挂载jsonpCallback
1335
1355
  source.add('// process ali subpackages runtime in root chunk\n' +
1336
- 'var context = (function() { return this })() || Function("return this")();\n\n')
1337
- source.add(`context[${JSON.stringify(chunkLoadingGlobal)}] = ${globalObject}[${JSON.stringify(chunkLoadingGlobal)}] = require("${relativePath}");\n`)
1356
+ 'var context = (function() { return this })() || Function("return this")();\n')
1357
+ source.add(`context[${chunkLoadingGlobalStr}] = ${globalObject}[${chunkLoadingGlobalStr}] = require("${relativePath}");\n`)
1338
1358
  } else {
1339
1359
  // 其余chunk中通过context全局传递runtime
1340
1360
  source.add('// process ali subpackages runtime in other chunk\n' +
1341
- 'var context = (function() { return this })() || Function("return this")();\n\n')
1342
- source.add(`${globalObject}[${JSON.stringify(chunkLoadingGlobal)}] = context[${JSON.stringify(chunkLoadingGlobal)}];\n`)
1361
+ 'var context = (function() { return this })() || Function("return this")();\n')
1362
+ source.add(`${globalObject}[${chunkLoadingGlobalStr}] = context[${chunkLoadingGlobalStr}];\n`)
1343
1363
  }
1344
1364
  } else {
1345
- source.add(`${globalObject}[${JSON.stringify(chunkLoadingGlobal)}] = require("${relativePath}");\n`)
1365
+ source.add(`${globalObject}[${chunkLoadingGlobalStr}] = require("${relativePath}");\n`)
1346
1366
  }
1347
1367
  } else {
1348
1368
  source.add(`require("${relativePath}");\n`)
@@ -1350,10 +1370,11 @@ class MpxWebpackPlugin {
1350
1370
  })
1351
1371
 
1352
1372
  if (isRuntime) {
1353
- source.add('var context = (function() { return this })() || Function("return this")();\n')
1354
- source.add(`
1373
+ if (mpx.mode === 'ali' || mpx.mode === 'qq') {
1374
+ source.add(`
1355
1375
  // Fix babel runtime in some quirky environment like ali & qq dev.
1356
1376
  try {
1377
+ var context = (function() { return this })() || Function("return this")();
1357
1378
  if(!context.console){
1358
1379
  context.console = console;
1359
1380
  context.setInterval = setInterval;
@@ -1394,8 +1415,9 @@ try {
1394
1415
  }
1395
1416
  } catch(e){
1396
1417
  }\n`)
1418
+ }
1397
1419
  source.add(originalSource)
1398
- source.add(`\nmodule.exports = ${globalObject}[${JSON.stringify(chunkLoadingGlobal)}];\n`)
1420
+ source.add(`\nmodule.exports = ${globalObject}[${chunkLoadingGlobalStr}];\n`)
1399
1421
  } else {
1400
1422
  source.add(originalSource)
1401
1423
  }
@@ -22,6 +22,7 @@ module.exports = function createJSONHelper ({ loaderContext, emitWarning, custom
22
22
 
23
23
  const isUrlRequest = r => isUrlRequestRaw(r, root, externals)
24
24
  const urlToRequest = r => loaderUtils.urlToRequest(r)
25
+ const isScript = ext => /\.(ts|js)$/.test(ext)
25
26
 
26
27
  const dynamicEntryMap = new Map()
27
28
 
@@ -73,7 +74,7 @@ module.exports = function createJSONHelper ({ loaderContext, emitWarning, custom
73
74
  const resourceName = path.join(parsed.dir, parsed.name)
74
75
 
75
76
  if (!outputPath) {
76
- if (ext === '.js' && resourceName.includes('node_modules') && mode !== 'web') {
77
+ if (isScript(ext) && resourceName.includes('node_modules') && mode !== 'web') {
77
78
  let root = info.descriptionFileRoot
78
79
  let name = 'nativeComponent'
79
80
  if (info.descriptionFileData) {
@@ -91,7 +92,7 @@ module.exports = function createJSONHelper ({ loaderContext, emitWarning, custom
91
92
  outputPath = getOutputPath(resourcePath, 'component')
92
93
  }
93
94
  }
94
- if (ext === '.js' && mode !== 'web') {
95
+ if (isScript(ext) && mode !== 'web') {
95
96
  resource = `!!${nativeLoaderPath}!${resource}`
96
97
  }
97
98
 
@@ -131,7 +132,7 @@ module.exports = function createJSONHelper ({ loaderContext, emitWarning, custom
131
132
  outputPath = /^(.*?)(\.[^.]*)?$/.exec(relative)[1]
132
133
  }
133
134
  }
134
- if (ext === '.js' && mode !== 'web') {
135
+ if (isScript(ext) && mode !== 'web') {
135
136
  resource = `!!${nativeLoaderPath}!${resource}`
136
137
  }
137
138
  const entry = getDynamicEntry(resource, 'page', outputPath, tarRoot, publicPath + tarRoot)
@@ -8,7 +8,7 @@ const async = require('async')
8
8
  const { matchCondition } = require('./utils/match-condition')
9
9
  const { JSON_JS_EXT } = require('./utils/const')
10
10
  const getRulesRunner = require('./platform')
11
-
11
+ // todo native-loader考虑与mpx-loader或加强复用,原生组件约等于4个区块都为src的.mpx文件
12
12
  module.exports = function (content) {
13
13
  this.cacheable()
14
14
 
@@ -44,6 +44,8 @@ module.exports = function (content) {
44
44
  scss: '.scss'
45
45
  }
46
46
 
47
+ const TS_EXT = '.ts'
48
+
47
49
  let useJSONJS = false
48
50
  let cssLang = ''
49
51
  const hasScoped = (queryObj.scoped || autoScope) && mode === 'ali'
@@ -54,7 +56,7 @@ module.exports = function (content) {
54
56
  this.resolve(parsed.dir, resourceName + extName, callback)
55
57
  }
56
58
 
57
- function checkCSSLangFiles (callback) {
59
+ function checkCSSLangFile (callback) {
58
60
  const langs = mpx.nativeConfig.cssLangs || ['less', 'stylus', 'scss', 'sass']
59
61
  const results = []
60
62
  async.eachOf(langs, function (lang, i, callback) {
@@ -89,6 +91,15 @@ module.exports = function (content) {
89
91
  })
90
92
  }
91
93
 
94
+ function checkTSFile (callback) {
95
+ checkFileExists(TS_EXT, (err, result) => {
96
+ if (!err && result) {
97
+ typeResourceMap.script = result
98
+ }
99
+ callback()
100
+ })
101
+ }
102
+
92
103
  const emitWarning = (msg) => {
93
104
  this.emitWarning(
94
105
  new Error('[native-loader][' + this.resource + ']: ' + msg)
@@ -105,15 +116,16 @@ module.exports = function (content) {
105
116
  async.waterfall([
106
117
  (callback) => {
107
118
  async.parallel([
108
- checkCSSLangFiles,
109
- checkJSONJSFile
119
+ checkCSSLangFile,
120
+ checkJSONJSFile,
121
+ checkTSFile
110
122
  ], (err) => {
111
123
  callback(err)
112
124
  })
113
125
  },
114
126
  (callback) => {
115
127
  async.forEachOf(typeExtMap, (ext, key, callback) => {
116
- // 检测到jsonjs或cssLang时跳过对应类型文件检测
128
+ // 对应资源存在预处理类型文件时跳过对应的标准文件检测
117
129
  if (typeResourceMap[key]) {
118
130
  return callback()
119
131
  }
@@ -70,6 +70,19 @@ module.exports = function getSpec ({ warn, error }) {
70
70
  return input
71
71
  }
72
72
 
73
+ // 校验输出支付宝 componentGenerics 配置的正确性
74
+ function aliComponentGenericsValidate (input) {
75
+ const componentGenerics = input.componentGenerics
76
+ if (componentGenerics && typeof componentGenerics === 'object') {
77
+ Object.keys(componentGenerics).forEach(key => {
78
+ if (!componentGenerics[key].default) {
79
+ error(`Ali environment componentGenerics need to specify a default custom component! please check the configuration of component ${key}`)
80
+ }
81
+ })
82
+ }
83
+ return input
84
+ }
85
+
73
86
  function fillGlobalComponents (input, { globalComponents }) {
74
87
  if (globalComponents) {
75
88
  Object.assign(globalComponents, input.usingComponents)
@@ -115,7 +128,7 @@ module.exports = function getSpec ({ warn, error }) {
115
128
  const componentRules = [
116
129
  {
117
130
  test: 'componentGenerics',
118
- ali: deletePath(true)
131
+ ali: aliComponentGenericsValidate
119
132
  },
120
133
  {
121
134
  test: 'componentPlaceholder',
@@ -144,20 +144,8 @@ export function inheritEvent (type, oe, detail = {}) {
144
144
  }
145
145
 
146
146
  export function getCustomEvent (type, detail = {}, target = null) {
147
- const targetInfo = {}
148
- if (target) {
149
- const targetEl = target.$el || {}
150
- const info = {
151
- id: targetEl.id || '',
152
- dataset: targetEl.dataset || {},
153
- offsetTop: targetEl.offsetTop || 0,
154
- offsetLeft: targetEl.offsetLeft || 0
155
- }
156
- Object.assign(targetInfo, {
157
- target: info,
158
- currentTarget: info
159
- })
160
- }
147
+ const targetEl = (target && target.$el) || null
148
+ const targetInfo = targetEl ? { target: targetEl, currentTarget: targetEl } : {}
161
149
  return {
162
150
  type,
163
151
  detail,
@@ -1,13 +1,13 @@
1
1
  <template>
2
- <div class="mpx-movable-scroll-content" ref="scrollContent">
3
- <div class="mpx-movable-scroll-item">
4
- <slot></slot>
5
- </div>
2
+ <div class="mpx-movable-scroll-content" ref="scrollContent">
3
+ <div class="mpx-movable-scroll-item">
4
+ <slot></slot>
6
5
  </div>
6
+ </div>
7
7
  </template>
8
8
 
9
9
  <script type="text/ecmascript-6">
10
- import {getCustomEvent} from './getInnerListeners'
10
+ import {getCustomEvent, extendEvent} from './getInnerListeners'
11
11
  import BScroll from '@better-scroll/core'
12
12
  import Movable from '@better-scroll/movable'
13
13
  import Zoom from '@better-scroll/zoom'
@@ -121,6 +121,13 @@
121
121
  newVal = 0.5
122
122
  }
123
123
  this.bs.zoomTo(newVal, 'center', 'center')
124
+ },
125
+ disabled (newVal) {
126
+ if (newVal) {
127
+ this.bs && this.bs.disable()
128
+ } else {
129
+ this.bs && this.bs.enable()
130
+ }
124
131
  }
125
132
  },
126
133
  mounted () {
@@ -204,6 +211,14 @@
204
211
  this.bs.movingDirectionY = -1
205
212
  }
206
213
  })
214
+ actionsHandlerHooks.on('start', (e) => {
215
+ extendEvent(e, { detail: Object.assign({}, e.detail) })
216
+ this.$emit('touchstart', e)
217
+ })
218
+ actionsHandlerHooks.on('end', (e) => {
219
+ extendEvent(e, { detail: Object.assign({}, e.detail) })
220
+ this.$emit('touchend', e)
221
+ })
207
222
  actionsHandlerHooks.on('move', ({ deltaX, deltaY, e }) => {
208
223
  if (this.isZooming) {
209
224
  return
@@ -215,7 +230,9 @@
215
230
  this.touchEvent = 'vtouchmove'
216
231
  }
217
232
  }
218
- this.$emit(this.touchEvent, getCustomEvent(this.touchEvent, {}, this))
233
+ extendEvent(e, { detail: Object.assign({}, e.detail), currentTarget: e.target })
234
+ this.$emit(this.touchEvent, e)
235
+ this.$emit('touchmove', e)
219
236
  this.isFirstTouch = false
220
237
  })
221
238
  if (this.inertia) { // movable-view是否带有惯性
@@ -302,7 +319,9 @@
302
319
  }
303
320
  </script>
304
321
  <style lang="stylus" rel="stylesheet/stylus" scoped>
305
- .mpx-movable-scroll-content {
306
- position: absolute
307
- }
322
+ .mpx-movable-scroll-content
323
+ position: absolute
324
+ .mpx-movable-scroll-item
325
+ width: 100%
326
+ height: 100%
308
327
  </style>
@@ -163,7 +163,7 @@
163
163
  height: 100%
164
164
  overflow: hidden
165
165
  text-align: center
166
- font-size: 14px
166
+ font-size: 16px
167
167
  position: relative
168
168
 
169
169
  &.mpx-picker-fade-enter, &.mpx-picker-fade-leave-active
@@ -264,10 +264,9 @@
264
264
  },
265
265
  initLayerComputed () {
266
266
  const wrapper = this.$refs.wrapper
267
- const wrapperWidth = wrapper.offsetWidth
268
- const wrapperHeight = wrapper.offsetHeight
269
- this.$refs.innerWrapper.style.width = `${wrapperWidth}px`
270
- this.$refs.innerWrapper.style.height = `${wrapperHeight}px`
267
+ const computedStyle = getComputedStyle(wrapper)
268
+ this.$refs.innerWrapper.style.width = `${computedStyle.clientWidth - parseInt(computedStyle.paddingLeft) - parseInt(computedStyle.paddingRight)}px`
269
+ this.$refs.innerWrapper.style.height = `${computedStyle.clientHeight - parseInt(computedStyle.paddingTop) - parseInt(computedStyle.paddingBottom)}px`
271
270
  const innerWrapper = this.$refs.innerWrapper
272
271
  const childrenArr = Array.from(innerWrapper.children)
273
272
 
@@ -146,6 +146,11 @@
146
146
  classList: ''
147
147
  }
148
148
  },
149
+ watch: {
150
+ muted (val) {
151
+ this.mutedCopy = val
152
+ }
153
+ },
149
154
  mounted () {
150
155
  this.initStyle()
151
156
  this.initEvent()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.8.47",
3
+ "version": "2.8.49",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"
@@ -29,7 +29,6 @@
29
29
  "@better-scroll/zoom": "^2.5.1",
30
30
  "acorn-walk": "^7.2.0",
31
31
  "async": "^2.6.0",
32
- "consolidate": "^0.15.1",
33
32
  "css": "^2.2.1",
34
33
  "css-selector-tokenizer": "^0.7.0",
35
34
  "cssnano": "^5.0.16",
@@ -82,5 +81,5 @@
82
81
  "engines": {
83
82
  "node": ">=14.14.0"
84
83
  },
85
- "gitHead": "9069d7f3931841a7e3acaf990464813a3b6ccb0c"
84
+ "gitHead": "b399e81951df7094fb0a494ae877bcf4e6a2985b"
86
85
  }
@@ -1,29 +0,0 @@
1
- // loader for pre-processing templates with e.g. pug
2
-
3
- const cons = require('consolidate')
4
- const loaderUtils = require('loader-utils')
5
-
6
- module.exports = function (content) {
7
- this.cacheable && this.cacheable()
8
- const callback = this.async()
9
- const opt = loaderUtils.getOptions(this) || {}
10
-
11
- if (!cons[opt.engine]) {
12
- return callback(new Error(
13
- 'Template engine \'' + opt.engine + '\' ' +
14
- 'isn\'t available in Consolidate.js'
15
- ))
16
- }
17
-
18
- const templateOption = opt.templateOption
19
-
20
- // for relative includes
21
- templateOption.filename = this.resourcePath
22
-
23
- cons[opt.engine].render(content, templateOption, function (err, html) {
24
- if (err) {
25
- return callback(err)
26
- }
27
- callback(null, html)
28
- })
29
- }