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

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.
Files changed (63) hide show
  1. package/lib/dependencies/CommonJsExtractDependency.js +51 -0
  2. package/lib/dependencies/DynamicEntryDependency.js +10 -16
  3. package/lib/dependencies/ResolveDependency.js +11 -20
  4. package/lib/extractor.js +1 -0
  5. package/lib/helpers.js +9 -1
  6. package/lib/index.js +239 -134
  7. package/lib/json-compiler/helper.js +27 -17
  8. package/lib/json-compiler/index.js +82 -31
  9. package/lib/loader.js +31 -37
  10. package/lib/native-loader.js +21 -14
  11. package/lib/parser.js +0 -1
  12. package/lib/platform/index.js +15 -4
  13. package/lib/platform/json/wx/index.js +63 -2
  14. package/lib/platform/run-rules.js +1 -1
  15. package/lib/platform/template/normalize-component-rules.js +42 -41
  16. package/lib/platform/template/wx/component-config/README.md +1 -1
  17. package/lib/platform/template/wx/component-config/component.js +1 -2
  18. package/lib/platform/template/wx/component-config/fix-component-name.js +21 -0
  19. package/lib/platform/template/wx/component-config/hypen-tag-name.js +2 -6
  20. package/lib/platform/template/wx/component-config/index.js +6 -4
  21. package/lib/platform/template/wx/component-config/view.js +0 -11
  22. package/lib/platform/template/wx/index.js +84 -32
  23. package/lib/runtime/base.styl +9 -6
  24. package/lib/runtime/components/web/filterTag.js +9 -30
  25. package/lib/runtime/components/web/getInnerListeners.js +3 -16
  26. package/lib/runtime/components/web/mpx-image.vue +13 -10
  27. package/lib/runtime/components/web/mpx-keep-alive.vue +10 -17
  28. package/lib/runtime/components/web/mpx-movable-view.vue +105 -23
  29. package/lib/runtime/components/web/mpx-picker-view-column.vue +10 -2
  30. package/lib/runtime/components/web/mpx-picker-view.vue +1 -1
  31. package/lib/runtime/components/web/mpx-picker.vue +9 -1
  32. package/lib/runtime/components/web/mpx-scroll-view.vue +69 -23
  33. package/lib/runtime/components/web/mpx-swiper.vue +152 -62
  34. package/lib/runtime/components/web/mpx-video.vue +123 -89
  35. package/lib/runtime/components/web/mpx-web-view.vue +120 -81
  36. package/lib/runtime/components/web/promisify.js +19 -0
  37. package/lib/runtime/components/wx/default-page.mpx +27 -0
  38. package/lib/runtime/optionProcessor.js +321 -270
  39. package/lib/runtime/stringify.wxs +44 -8
  40. package/lib/style-compiler/index.js +6 -3
  41. package/lib/template-compiler/bind-this.js +280 -49
  42. package/lib/template-compiler/compiler.js +122 -108
  43. package/lib/template-compiler/index.js +35 -23
  44. package/lib/utils/check-core-version-match.js +18 -14
  45. package/lib/utils/dom-tag-config.js +115 -0
  46. package/lib/utils/make-map.js +12 -0
  47. package/lib/utils/string.js +7 -1
  48. package/lib/utils/ts-loader-watch-run-loader-filter.js +4 -5
  49. package/lib/web/processJSON.js +39 -3
  50. package/lib/web/processMainScript.js +84 -0
  51. package/lib/web/processScript.js +21 -201
  52. package/lib/web/processTemplate.js +11 -35
  53. package/lib/web/script-helper.js +202 -0
  54. package/package.json +7 -6
  55. package/lib/json-compiler/default-page.mpx +0 -3
  56. package/lib/style-compiler/plugins/trim.js +0 -15
  57. package/lib/template-compiler/preprocessor.js +0 -29
  58. package/lib/wxss/compile-exports.js +0 -52
  59. package/lib/wxss/createResolver.js +0 -36
  60. package/lib/wxss/css-base.js +0 -79
  61. package/lib/wxss/getLocalIdent.js +0 -25
  62. package/lib/wxss/localsLoader.js +0 -44
  63. package/lib/wxss/processCss.js +0 -274
@@ -0,0 +1,51 @@
1
+ const ModuleDependency = require('webpack/lib/dependencies/ModuleDependency')
2
+ const makeSerializable = require('webpack/lib/util/makeSerializable')
3
+
4
+ class CommonJsExtractDependency extends ModuleDependency {
5
+ constructor (request, range) {
6
+ super(request)
7
+ this.range = range
8
+ }
9
+
10
+ get type () {
11
+ return 'mpx cjs extract'
12
+ }
13
+
14
+ get category () {
15
+ return 'commonjs'
16
+ }
17
+ }
18
+
19
+ CommonJsExtractDependency.Template = class CommonJsExtractDependencyTemplate extends (
20
+ ModuleDependency.Template
21
+ ) {
22
+ apply (
23
+ dep,
24
+ source,
25
+ {
26
+ runtimeTemplate,
27
+ moduleGraph,
28
+ chunkGraph,
29
+ runtimeRequirements
30
+ }
31
+ ) {
32
+ let content = ''
33
+ if (!dep.weak) {
34
+ content = runtimeTemplate.moduleExports({
35
+ module: moduleGraph.getModule(dep),
36
+ chunkGraph,
37
+ request: dep.request,
38
+ weak: dep.weak,
39
+ runtimeRequirements
40
+ })
41
+ }
42
+ source.replace(dep.range[0], dep.range[1] - 1, content)
43
+ }
44
+ }
45
+
46
+ makeSerializable(
47
+ CommonJsExtractDependency,
48
+ '@mpxjs/webpack-plugin/lib/dependencies/CommonJsExtractDependency'
49
+ )
50
+
51
+ module.exports = CommonJsExtractDependency
@@ -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)
@@ -1,6 +1,7 @@
1
1
  const NullDependency = require('webpack/lib/dependencies/NullDependency')
2
2
  const parseRequest = require('../utils/parse-request')
3
3
  const makeSerializable = require('webpack/lib/util/makeSerializable')
4
+ const { matchCondition } = require('../utils/match-condition')
4
5
 
5
6
  class ResolveDependency extends NullDependency {
6
7
  constructor (resource, packageName, issuerResource, range) {
@@ -22,39 +23,29 @@ class ResolveDependency extends NullDependency {
22
23
  }
23
24
 
24
25
  getResolved () {
25
- const { resource, packageName, compilation } = this
26
+ const { resource, packageName, compilation, issuerResource } = this
26
27
  if (!compilation) return ''
27
28
  const mpx = compilation.__mpx__
28
29
  if (!mpx) return ''
29
- const { pagesMap, componentsMap, staticResourcesMap } = mpx
30
+ const { pagesMap, componentsMap, staticResourcesMap, partialCompile } = mpx
30
31
  const { resourcePath } = parseRequest(resource)
31
32
  const currentComponentsMap = componentsMap[packageName]
32
33
  const mainComponentsMap = componentsMap.main
33
34
  const currentStaticResourcesMap = staticResourcesMap[packageName]
34
35
  const mainStaticResourcesMap = staticResourcesMap.main
35
- return pagesMap[resourcePath] || currentComponentsMap[resourcePath] || mainComponentsMap[resourcePath] || currentStaticResourcesMap[resourcePath] || mainStaticResourcesMap[resourcePath] || ''
36
- }
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]
36
+ const resolveResult = pagesMap[resourcePath] || currentComponentsMap[resourcePath] || mainComponentsMap[resourcePath] || currentStaticResourcesMap[resourcePath] || mainStaticResourcesMap[resourcePath] || ''
37
+ if (!resolveResult) {
38
+ if (!partialCompile || matchCondition(resourcePath, partialCompile)) {
39
+ compilation.errors.push(new Error(`Path ${resource} is not a page/component/static resource, which is resolved from ${issuerResource}!`))
40
+ }
41
+ }
42
+ return resolveResult
45
43
  }
46
44
 
47
45
  // resolved可能会动态变更,需用此更新hash
48
46
  updateHash (hash, context) {
49
47
  this.resolved = this.getResolved()
50
- const { resource, issuerResource, compilation } = this
51
- if (this.resolved) {
52
- hash.update(this.resolved)
53
- } 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
- }
57
- }
48
+ hash.update(this.resolved)
58
49
  super.updateHash(hash, context)
59
50
  }
60
51
 
package/lib/extractor.js CHANGED
@@ -116,5 +116,6 @@ module.exports.pitch = async function (remainingRequest) {
116
116
  }
117
117
  }
118
118
 
119
+ if (!resultSource) buildInfo.isEmpty = true
119
120
  return resultSource
120
121
  }
package/lib/helpers.js CHANGED
@@ -20,7 +20,15 @@ module.exports = function createHelpers (loaderContext) {
20
20
  const { mode, env } = loaderContext.getMpx() || {}
21
21
 
22
22
  function getRequire (type, part, extraOptions, index) {
23
- return 'require(' + getRequestString(type, part, extraOptions, index) + ')'
23
+ let extract = false
24
+ switch (type) {
25
+ // eslint-disable-next-line no-fallthrough
26
+ case 'json':
27
+ case 'styles':
28
+ case 'template':
29
+ extract = true
30
+ }
31
+ return (extract ? 'require.extract(' : 'require(') + getRequestString(type, part, extraOptions, index) + ')'
24
32
  }
25
33
 
26
34
  function getImport (type, part, extraOptions, index) {