@mpxjs/webpack-plugin 2.10.18 → 2.10.20

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 (70) hide show
  1. package/lib/dependencies/ResolveDependency.js +2 -2
  2. package/lib/index.js +25 -6
  3. package/lib/json-compiler/helper.js +11 -10
  4. package/lib/json-compiler/index.js +7 -4
  5. package/lib/json-compiler/plugin.js +4 -4
  6. package/lib/loader.js +4 -4
  7. package/lib/native-loader.js +4 -4
  8. package/lib/platform/create-diagnostic.js +168 -0
  9. package/lib/platform/index.js +16 -3
  10. package/lib/platform/json/wx/index.js +66 -17
  11. package/lib/platform/run-rules.js +9 -5
  12. package/lib/platform/style/wx/index.js +4 -3
  13. package/lib/platform/template/normalize-component-rules.js +7 -9
  14. package/lib/platform/template/wx/component-config/camera.js +12 -0
  15. package/lib/platform/template/wx/component-config/custom-built-in-component.js +34 -0
  16. package/lib/platform/template/wx/component-config/index.js +18 -3
  17. package/lib/platform/template/wx/component-config/input.js +1 -7
  18. package/lib/platform/template/wx/component-config/movable-view.js +1 -7
  19. package/lib/platform/template/wx/component-config/text.js +1 -1
  20. package/lib/platform/template/wx/component-config/textarea.js +1 -25
  21. package/lib/platform/template/wx/component-config/unsupported.js +1 -1
  22. package/lib/platform/template/wx/index.js +48 -34
  23. package/lib/react/processJSON.js +7 -4
  24. package/lib/react/processStyles.js +22 -8
  25. package/lib/react/processTemplate.js +85 -41
  26. package/lib/react/style-helper.js +120 -85
  27. package/lib/react/template-loader.js +148 -0
  28. package/lib/runtime/components/react/dist/mpx-async-suspense.jsx +1 -1
  29. package/lib/runtime/components/react/dist/mpx-camera.d.ts +31 -0
  30. package/lib/runtime/components/react/dist/mpx-camera.jsx +270 -0
  31. package/lib/runtime/components/react/dist/mpx-image.d.ts +0 -1
  32. package/lib/runtime/components/react/dist/mpx-image.jsx +1 -2
  33. package/lib/runtime/components/react/dist/mpx-picker/type.d.ts +1 -1
  34. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +92 -15
  35. package/lib/runtime/components/react/dist/mpx-web-view.jsx +1 -1
  36. package/lib/runtime/components/react/dist/utils.jsx +3 -2
  37. package/lib/runtime/components/react/mpx-async-suspense.tsx +2 -1
  38. package/lib/runtime/components/react/mpx-camera.tsx +358 -0
  39. package/lib/runtime/components/react/mpx-image.tsx +1 -3
  40. package/lib/runtime/components/react/mpx-picker/type.ts +1 -1
  41. package/lib/runtime/components/react/mpx-scroll-view.tsx +106 -16
  42. package/lib/runtime/components/react/mpx-web-view.tsx +1 -1
  43. package/lib/runtime/components/react/utils.tsx +3 -2
  44. package/lib/runtime/components/wx/default-component.mpx +9 -0
  45. package/lib/runtime/components/wx/default-page.mpx +3 -11
  46. package/lib/runtime/optionProcessor.d.ts +2 -0
  47. package/lib/runtime/optionProcessor.js +77 -1
  48. package/lib/style-compiler/index.js +2 -0
  49. package/lib/style-compiler/plugins/remove-strip-conditional-comments.js +14 -0
  50. package/lib/style-compiler/strip-conditional.js +40 -26
  51. package/lib/template-compiler/compiler.js +274 -116
  52. package/lib/template-compiler/gen-node-react.js +35 -7
  53. package/lib/template-compiler/index.js +9 -7
  54. package/lib/utils/const.js +4 -1
  55. package/lib/utils/dom-tag-config.js +1 -1
  56. package/lib/utils/partial-compile-rules.js +27 -0
  57. package/lib/utils/pre-process-json.js +3 -0
  58. package/lib/utils/source-location.js +96 -0
  59. package/lib/web/compile-wx-template-fragment.js +68 -0
  60. package/lib/web/index.js +2 -0
  61. package/lib/web/processJSON.js +7 -4
  62. package/lib/web/processScript.js +41 -3
  63. package/lib/web/processTemplate.js +61 -19
  64. package/lib/web/template-loader.js +123 -0
  65. package/lib/web/template-shared.js +48 -0
  66. package/lib/wxml/loader.js +3 -2
  67. package/lib/wxss/loader.js +1 -1
  68. package/lib/wxss/utils.js +6 -4
  69. package/package.json +12 -4
  70. package/lib/platform/template/wx/component-config/component.js +0 -41
@@ -0,0 +1,123 @@
1
+ const loaderUtils = require('loader-utils')
2
+ const addQuery = require('../utils/add-query')
3
+ const parseRequest = require('../utils/parse-request')
4
+ const { matchCondition } = require('../utils/match-condition')
5
+ const templateCompiler = require('../template-compiler/compiler')
6
+ const { getWxTemplateComponentName, serializeWxTemplateDefinition, buildWebTemplateImportMergeExpr } = require('./template-shared')
7
+ const { compileTemplateFragment, wrapCreateTemplateComponentWithBlock } = require('./compile-wx-template-fragment')
8
+ const normalize = require('../utils/normalize')
9
+ const optionProcessorPath = normalize.lib('runtime/optionProcessor')
10
+
11
+ module.exports = function (content) {
12
+ const loaderContext = this
13
+ const isProduction = loaderContext.mode === 'production'
14
+ const mpx = loaderContext.getMpx()
15
+
16
+ const {
17
+ projectRoot,
18
+ mode,
19
+ srcMode,
20
+ env,
21
+ defs,
22
+ wxsContentMap,
23
+ decodeHTMLText,
24
+ externalClasses,
25
+ autoVirtualHostRules,
26
+ forceProxyEventRules,
27
+ checkUsingComponentsRules,
28
+ globalComponents,
29
+ webConfig
30
+ } = mpx
31
+
32
+ const { resourcePath, rawResourcePath, queryObj } = parseRequest(loaderContext.resource)
33
+
34
+ const warn = (msg, loc) => {
35
+ loaderContext.emitWarning(
36
+ new Error('[Mpx template warning][' + (loc || loaderContext.resourcePath) + ']: ' + msg)
37
+ )
38
+ }
39
+ const error = (msg, loc) => {
40
+ loaderContext.emitError(
41
+ new Error('[Mpx template error][' + (loc || loaderContext.resourcePath) + ']: ' + msg)
42
+ )
43
+ }
44
+
45
+ const { meta } = templateCompiler.parse(content, {
46
+ warn,
47
+ error,
48
+ mode,
49
+ srcMode: queryObj.srcMode || srcMode,
50
+ env,
51
+ defs,
52
+ decodeHTMLText,
53
+ externalClasses,
54
+ filePath: rawResourcePath,
55
+ i18n: null,
56
+ globalComponents: Object.keys(globalComponents || {}),
57
+ hasVirtualHost: matchCondition(resourcePath, autoVirtualHostRules),
58
+ forceProxyEvent: matchCondition(resourcePath, forceProxyEventRules),
59
+ checkUsingComponents: matchCondition(resourcePath, checkUsingComponentsRules),
60
+ customBuiltInComponents: webConfig && webConfig.customBuiltInComponents
61
+ })
62
+
63
+ if (meta.wxsContentMap && wxsContentMap) {
64
+ for (const module in meta.wxsContentMap) {
65
+ wxsContentMap[`${rawResourcePath}~${module}`] = meta.wxsContentMap[module]
66
+ }
67
+ }
68
+
69
+ const builtInPaths = meta.builtInComponentsMap || {}
70
+ const builtInEntries = []
71
+ Object.keys(builtInPaths).forEach((name) => {
72
+ const request = addQuery(builtInPaths[name], { isComponent: true })
73
+ const req = loaderUtils.stringifyRequest(loaderContext, request)
74
+ builtInEntries.push(`${JSON.stringify(name)}: getComponent(require(${req}), {__mpxBuiltIn: true})`)
75
+ })
76
+ const builtInComponentsExpr = `{${builtInEntries.join(',')}}`
77
+
78
+ // 处理 imports:与 web/processTemplate、react/processTemplate 一致(urlToRequest + !!template-loader)
79
+ const importExprs = []
80
+ if (meta.imports) {
81
+ meta.imports.forEach((importSrc) => {
82
+ importExprs.push(buildWebTemplateImportMergeExpr(loaderContext, importSrc, projectRoot))
83
+ })
84
+ }
85
+
86
+ // 收集本 wxml 内声明的 wxs 模块,供其定义的模版组件使用
87
+ const wxsInitLines = []
88
+ if (meta.wxsModuleMap) {
89
+ Object.keys(meta.wxsModuleMap).forEach((module) => {
90
+ const src = loaderUtils.urlToRequest(meta.wxsModuleMap[module], projectRoot)
91
+ wxsInitLines.push(` __wxsModules[${JSON.stringify(module)}] = require(${loaderUtils.stringifyRequest(loaderContext, src)});`)
92
+ })
93
+ }
94
+
95
+ // 处理本地 template 定义
96
+ const localEntries = []
97
+ if (meta.templates) {
98
+ Object.keys(meta.templates).forEach((name) => {
99
+ const tplNode = meta.templates[name]
100
+ const tpl = serializeWxTemplateDefinition(tplNode, error, name)
101
+ const compiled = compileTemplateFragment(tpl, {
102
+ emitError: error,
103
+ definitionName: name,
104
+ resourcePath: rawResourcePath,
105
+ isProduction
106
+ })
107
+ const compName = getWxTemplateComponentName(name)
108
+ const inner = `name: ${JSON.stringify(compName)}, components: Object.assign({}, ${builtInComponentsExpr}), wxsModules: __wxsModules`
109
+ localEntries.push(`${JSON.stringify(compName)}: ${wrapCreateTemplateComponentWithBlock(compiled.block, inner)}`)
110
+ })
111
+ }
112
+ const localMapExpr = `{${localEntries.join(',')}}`
113
+
114
+ const output = `
115
+ var __optionProcessor = require(${loaderUtils.stringifyRequest(loaderContext, optionProcessorPath)});
116
+ var getComponent = __optionProcessor.getComponent;
117
+ var createTemplateComponent = __optionProcessor.createTemplateComponent;
118
+ var __wxsModules = {};
119
+ ${wxsInitLines.join('\n')}
120
+ module.exports = Object.assign({}, ${[...importExprs, localMapExpr].join(', ')});
121
+ `
122
+ return output
123
+ }
@@ -0,0 +1,48 @@
1
+ const loaderUtils = require('loader-utils')
2
+ const templateCompiler = require('../template-compiler/compiler')
3
+ const normalize = require('../utils/normalize')
4
+ const { MPX_TEMPLATE_COMPONENT_PREFIX } = require('../utils/const')
5
+
6
+ function getWxTemplateComponentName (definitionName) {
7
+ return MPX_TEMPLATE_COMPONENT_PREFIX + definitionName
8
+ }
9
+
10
+ /**
11
+ * 与 react/processTemplate 中 `<import src>` 一致:`urlToRequest` 解析相对路径后,经 `!!web/template-loader!` 拼出 require 表达式;该模块 `module.exports` 即为具名子组件映射,供 Object.assign 合并。
12
+ */
13
+ function buildWebTemplateImportMergeExpr (loaderContext, importSrc, projectRoot) {
14
+ const webTemplateLoaderPath = normalize.lib('web/template-loader')
15
+ const request = loaderUtils.urlToRequest(importSrc, projectRoot)
16
+ const req = loaderUtils.stringifyRequest(loaderContext, `!!${webTemplateLoaderPath}!${request}`)
17
+ return `(require(${req}) || {})`
18
+ }
19
+
20
+ /**
21
+ * 将 `<template name="...">` 定义节点的子树序列化为 wx 风格 web 模版组件可用的 HTML 字符串。
22
+ * 供 `template-loader`(独立 wxml 链)与 `processTemplate`(.mpx 主模版)共用,规则须保持一致。
23
+ *
24
+ * @param {*} tplNode template 定义 AST 节点
25
+ * @param {(msg: string) => void} emitError 已由调用方带上 [Mpx template error][resource] 等前缀
26
+ * @param {string} [definitionName] name shown in multi-root error; defaults to `tplNode.attrsMap.name`
27
+ * @returns {string}
28
+ */
29
+ function serializeWxTemplateDefinition (tplNode, emitError, definitionName) {
30
+ const realChildren = tplNode.children.filter(c => c.type === 1 && c.tag !== 'temp-node')
31
+ if (realChildren.length > 1) {
32
+ const name = definitionName != null ? definitionName : (tplNode.attrsMap && tplNode.attrsMap.name) || ''
33
+ emitError(
34
+ `Web mode does not support multi-root template definition${name ? ` "${name}"` : ''}; please wrap with a single root element.`
35
+ )
36
+ }
37
+ let content = ''
38
+ tplNode.children.forEach((child) => {
39
+ content += templateCompiler.serialize(child)
40
+ })
41
+ return content
42
+ }
43
+
44
+ module.exports = {
45
+ getWxTemplateComponentName,
46
+ serializeWxTemplateDefinition,
47
+ buildWebTemplateImportMergeExpr
48
+ }
@@ -23,6 +23,7 @@ module.exports = function (content) {
23
23
  const hasScoped = false
24
24
  const hasComment = false
25
25
  const isNative = false
26
+ const isStatic = true
26
27
 
27
28
  const mode = mpx.mode
28
29
  const localSrcMode = queryObj.mode
@@ -96,7 +97,7 @@ module.exports = function (content) {
96
97
  hasScoped,
97
98
  hasComment,
98
99
  isNative,
99
- isStatic: true
100
+ isStatic
100
101
  }
101
102
  requestString = getRequestString('template', { src, mode: localSrcMode }, extraOptions)
102
103
  break
@@ -104,7 +105,7 @@ module.exports = function (content) {
104
105
  // 显式传递issuerResource避免模块缓存以及提供给wxs-loader计算相对路径
105
106
  extraOptions = {
106
107
  issuerResource: this.resource,
107
- isStatic: true
108
+ isStatic
108
109
  }
109
110
  requestString = getRequestString('wxs', { src, mode: localSrcMode }, extraOptions)
110
111
  break
@@ -40,7 +40,7 @@ module.exports = async function loader (content, map, meta) {
40
40
  const mpx = this.getMpx()
41
41
  const externals = mpx.externals
42
42
  const root = mpx.projectRoot
43
- const sourceMap = mpx.cssSourceMap || false
43
+ const sourceMap = this.sourceMap
44
44
  const isRN = ['ios', 'android', 'harmony'].includes(mpx.mode)
45
45
 
46
46
  let options
package/lib/wxss/utils.js CHANGED
@@ -972,11 +972,13 @@ function normalizeSourceMapForRuntime (map, loaderContext) {
972
972
 
973
973
  const resourceDirname = path.dirname(loaderContext.resourcePath)
974
974
  const absoluteSource = path.resolve(resourceDirname, source)
975
- const contextifyPath = normalizePath(
976
- path.relative(loaderContext.rootContext, absoluteSource)
977
- )
975
+ // 为方便编译报错信息显示,直接返回绝对路径,后续如果有需要再改成 webpack://./xxx 的形式
976
+ return normalizePath(absoluteSource)
977
+ // const contextifyPath = normalizePath(
978
+ // path.relative(loaderContext.rootContext, absoluteSource)
979
+ // )
978
980
 
979
- return `webpack://./${contextifyPath}`
981
+ // return `webpack://./${contextifyPath}`
980
982
  })
981
983
  }
982
984
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.10.18",
3
+ "version": "2.10.20",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"
@@ -29,7 +29,7 @@
29
29
  "@better-scroll/wheel": "^2.5.1",
30
30
  "@better-scroll/zoom": "^2.5.1",
31
31
  "@mpxjs/template-engine": "^2.8.7",
32
- "@mpxjs/utils": "^2.10.18",
32
+ "@mpxjs/utils": "^2.10.20",
33
33
  "acorn": "^8.11.3",
34
34
  "acorn-walk": "^7.2.0",
35
35
  "async": "^2.6.0",
@@ -63,8 +63,14 @@
63
63
  "webpack-virtual-modules": "^0.6.0"
64
64
  },
65
65
  "peerDependencies": {
66
+ "vue": "^2.7.10",
66
67
  "webpack": "^5.75.0"
67
68
  },
69
+ "peerDependenciesMeta": {
70
+ "vue": {
71
+ "optional": true
72
+ }
73
+ },
68
74
  "publishConfig": {
69
75
  "registry": "https://registry.npmjs.org",
70
76
  "access": "public"
@@ -84,7 +90,7 @@
84
90
  },
85
91
  "devDependencies": {
86
92
  "@d11/react-native-fast-image": "^8.6.12",
87
- "@mpxjs/api-proxy": "^2.10.18",
93
+ "@mpxjs/api-proxy": "^2.10.20",
88
94
  "@types/babel-traverse": "^6.25.4",
89
95
  "@types/babel-types": "^7.0.4",
90
96
  "@types/glob": "^8.1.0",
@@ -97,12 +103,14 @@
97
103
  "react-native-safe-area-context": "^4.12.0",
98
104
  "react-native-svg": "^15.8.0",
99
105
  "react-native-video": "^6.9.0",
106
+ "react-native-vision-camera": "^4.7.2",
100
107
  "react-native-webview": "^13.12.2",
101
108
  "rimraf": "^6.0.1",
109
+ "vue": "^2.7.16",
102
110
  "webpack": "^5.75.0"
103
111
  },
104
112
  "engines": {
105
113
  "node": ">=14.14.0"
106
114
  },
107
- "gitHead": "8ce11a81959cb4b807d683b14c2d0b72c3991da3"
115
+ "gitHead": "929d7a7954124c436aa24e0a66f71512a0ea1c8e"
108
116
  }
@@ -1,41 +0,0 @@
1
- const TAG_NAME = 'component'
2
-
3
- /** is 属性格式化为中划线(-)连接 (弃用,新方案:https://github.com/didi/mpx/pull/2228) */
4
- // const formatPropIs = (obj, data) => {
5
- // const parsed = parseMustache(obj.value)
6
- // let value = parsed.result
7
- // if (parsed.hasBinding) value = value.slice(1, -1)
8
- // const el = data.el
9
- // if (el) {
10
- // const injectWxsProp = {
11
- // injectWxsPath: '~' + normalize.lib('runtime/utils.wxs'),
12
- // injectWxsModuleName: '__wxsUtils__'
13
- // }
14
- // if (el.injectWxsProps && Array.isArray(el.injectWxsProps)) {
15
- // el.injectWxsProps.push(injectWxsProp)
16
- // } else {
17
- // el.injectWxsProps = [injectWxsProp]
18
- // }
19
- // }
20
- // return {
21
- // name: 'is',
22
- // value: `{{__wxsUtils__.humpToLine(${value})}}`
23
- // }
24
- // }
25
-
26
- module.exports = function () {
27
- return {
28
- test: TAG_NAME,
29
- props: [
30
- // {
31
- // test: 'is',
32
- // ali (obj, data) {
33
- // return formatPropIs(obj, data)
34
- // },
35
- // swan (obj, data) {
36
- // return formatPropIs(obj, data)
37
- // }
38
- // }
39
- ]
40
- }
41
- }