@mpxjs/webpack-plugin 2.9.70-alpha.0 → 2.9.71

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 (126) hide show
  1. package/LICENSE +433 -0
  2. package/README.md +1 -1
  3. package/lib/config.js +0 -14
  4. package/lib/dependencies/ResolveDependency.js +0 -5
  5. package/lib/index.js +7 -38
  6. package/lib/json-compiler/helper.js +3 -3
  7. package/lib/loader.js +0 -53
  8. package/lib/parser.js +1 -1
  9. package/lib/platform/json/wx/index.js +21 -8
  10. package/lib/platform/style/wx/index.js +51 -54
  11. package/lib/platform/template/wx/component-config/button.js +2 -14
  12. package/lib/platform/template/wx/component-config/fix-component-name.js +15 -12
  13. package/lib/platform/template/wx/component-config/image.js +0 -4
  14. package/lib/platform/template/wx/component-config/index.js +1 -1
  15. package/lib/platform/template/wx/component-config/input.js +0 -4
  16. package/lib/platform/template/wx/component-config/movable-view.js +8 -1
  17. package/lib/platform/template/wx/component-config/picker-view.js +1 -5
  18. package/lib/platform/template/wx/component-config/rich-text.js +6 -2
  19. package/lib/platform/template/wx/component-config/scroll-view.js +1 -5
  20. package/lib/platform/template/wx/component-config/switch.js +0 -4
  21. package/lib/platform/template/wx/component-config/text.js +0 -4
  22. package/lib/platform/template/wx/component-config/textarea.js +0 -5
  23. package/lib/platform/template/wx/component-config/unsupported.js +1 -1
  24. package/lib/platform/template/wx/component-config/view.js +0 -4
  25. package/lib/platform/template/wx/index.js +1 -131
  26. package/lib/resolve-loader.js +1 -4
  27. package/lib/runtime/components/react/context.ts +8 -0
  28. package/lib/runtime/components/react/dist/context.js +2 -0
  29. package/lib/runtime/components/react/dist/getInnerListeners.js +39 -37
  30. package/lib/runtime/components/react/dist/mpx-button.jsx +16 -44
  31. package/lib/runtime/components/react/dist/mpx-canvas/html.js +2 -4
  32. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +5 -1
  33. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +93 -58
  34. package/lib/runtime/components/react/dist/mpx-navigator.jsx +1 -1
  35. package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +10 -14
  36. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +94 -81
  37. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +19 -16
  38. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +10 -11
  39. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +11 -4
  40. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +31 -8
  41. package/lib/runtime/components/react/dist/mpx-swiper.jsx +435 -371
  42. package/lib/runtime/components/react/dist/mpx-view.jsx +18 -53
  43. package/lib/runtime/components/react/dist/pickerFaces.js +3 -8
  44. package/lib/runtime/components/react/dist/pickerVIewContext.js +5 -0
  45. package/lib/runtime/components/react/dist/{pickerViewOverlay.jsx → pickerViewIndicator.jsx} +6 -6
  46. package/lib/runtime/components/react/dist/pickerViewMask.jsx +2 -2
  47. package/lib/runtime/components/react/dist/useAnimationHooks.js +27 -10
  48. package/lib/runtime/components/react/dist/utils.jsx +162 -70
  49. package/lib/runtime/components/react/event.config.ts +25 -26
  50. package/lib/runtime/components/react/getInnerListeners.ts +236 -182
  51. package/lib/runtime/components/react/mpx-button.tsx +27 -69
  52. package/lib/runtime/components/react/mpx-canvas/html.ts +2 -4
  53. package/lib/runtime/components/react/mpx-canvas/index.tsx +44 -46
  54. package/lib/runtime/components/react/mpx-checkbox-group.tsx +15 -13
  55. package/lib/runtime/components/react/mpx-checkbox.tsx +20 -21
  56. package/lib/runtime/components/react/mpx-form.tsx +15 -20
  57. package/lib/runtime/components/react/mpx-icon.tsx +2 -2
  58. package/lib/runtime/components/react/mpx-image.tsx +87 -47
  59. package/lib/runtime/components/react/mpx-input.tsx +24 -32
  60. package/lib/runtime/components/react/mpx-label.tsx +12 -14
  61. package/lib/runtime/components/react/mpx-movable-area.tsx +10 -16
  62. package/lib/runtime/components/react/mpx-movable-view.tsx +133 -92
  63. package/lib/runtime/components/react/mpx-navigator.tsx +3 -9
  64. package/lib/runtime/components/react/mpx-picker-view-column-item.tsx +76 -0
  65. package/lib/runtime/components/react/mpx-picker-view-column.tsx +206 -183
  66. package/lib/runtime/components/react/mpx-picker-view.tsx +49 -48
  67. package/lib/runtime/components/react/mpx-radio-group.tsx +13 -15
  68. package/lib/runtime/components/react/mpx-radio.tsx +19 -25
  69. package/lib/runtime/components/react/mpx-rich-text/html.ts +40 -0
  70. package/lib/runtime/components/react/mpx-rich-text/index.tsx +115 -0
  71. package/lib/runtime/components/react/mpx-root-portal.tsx +3 -5
  72. package/lib/runtime/components/react/mpx-scroll-view.tsx +53 -43
  73. package/lib/runtime/components/react/mpx-swiper-item.tsx +45 -11
  74. package/lib/runtime/components/react/mpx-swiper.tsx +742 -0
  75. package/lib/runtime/components/react/mpx-switch.tsx +19 -15
  76. package/lib/runtime/components/react/mpx-text.tsx +8 -16
  77. package/lib/runtime/components/react/mpx-textarea.tsx +11 -10
  78. package/lib/runtime/components/react/mpx-view.tsx +28 -77
  79. package/lib/runtime/components/react/mpx-web-view.tsx +94 -59
  80. package/lib/runtime/components/react/pickerFaces.ts +10 -7
  81. package/lib/runtime/components/react/pickerVIewContext.ts +27 -0
  82. package/lib/runtime/components/react/pickerViewIndicator.tsx +34 -0
  83. package/lib/runtime/components/react/pickerViewMask.tsx +30 -0
  84. package/lib/runtime/components/react/types/{getInnerListeners.ts → getInnerListeners.d.ts} +4 -5
  85. package/lib/runtime/components/react/types/global.d.ts +12 -1
  86. package/lib/runtime/components/react/useAnimationHooks.ts +60 -15
  87. package/lib/runtime/components/react/utils.tsx +175 -71
  88. package/lib/runtime/components/web/mpx-checkbox.vue +1 -1
  89. package/lib/runtime/components/web/mpx-picker-view-column.vue +9 -4
  90. package/lib/runtime/components/web/mpx-web-view.vue +34 -20
  91. package/lib/runtime/optionProcessor.js +0 -22
  92. package/lib/style-compiler/index.js +1 -1
  93. package/lib/style-compiler/plugins/scope-id.js +30 -2
  94. package/lib/template-compiler/compiler.js +91 -39
  95. package/lib/utils/env.js +1 -6
  96. package/lib/utils/pre-process-json.js +9 -5
  97. package/lib/wxss/loader.js +15 -2
  98. package/package.json +4 -7
  99. package/lib/dependencies/AddEntryDependency.js +0 -24
  100. package/lib/runtime/components/react/dist/types/common.js +0 -1
  101. package/lib/runtime/components/react/dist/types/getInnerListeners.js +0 -1
  102. package/lib/runtime/components/react/mpx-swiper/carouse.tsx +0 -527
  103. package/lib/runtime/components/react/mpx-swiper/index.tsx +0 -80
  104. package/lib/runtime/components/react/mpx-swiper/type.ts +0 -87
  105. package/lib/runtime/components/react/pickerOverlay.tsx +0 -32
  106. package/lib/runtime/components/tenon/getInnerListeners.js +0 -334
  107. package/lib/runtime/components/tenon/tenon-button.vue +0 -309
  108. package/lib/runtime/components/tenon/tenon-image.vue +0 -66
  109. package/lib/runtime/components/tenon/tenon-input.vue +0 -171
  110. package/lib/runtime/components/tenon/tenon-rich-text.vue +0 -26
  111. package/lib/runtime/components/tenon/tenon-scroll-view.vue +0 -127
  112. package/lib/runtime/components/tenon/tenon-switch.vue +0 -96
  113. package/lib/runtime/components/tenon/tenon-text.vue +0 -70
  114. package/lib/runtime/components/tenon/tenon-textarea.vue +0 -86
  115. package/lib/runtime/components/tenon/tenon-view.vue +0 -93
  116. package/lib/runtime/components/web/event.js +0 -105
  117. package/lib/runtime/optionProcessor.tenon.js +0 -84
  118. package/lib/style-compiler/plugins/hm.js +0 -20
  119. package/lib/tenon/index.js +0 -117
  120. package/lib/tenon/processJSON.js +0 -352
  121. package/lib/tenon/processScript.js +0 -203
  122. package/lib/tenon/processStyles.js +0 -21
  123. package/lib/tenon/processTemplate.js +0 -126
  124. package/lib/tenon/script-helper.js +0 -223
  125. package/lib/utils/get-relative-path.js +0 -25
  126. /package/lib/runtime/components/react/types/{common.ts → common.d.ts} +0 -0
@@ -1,352 +0,0 @@
1
- const async = require('async')
2
- const path = require('path')
3
- const JSON5 = require('json5')
4
- const loaderUtils = require('loader-utils')
5
- const parseRequest = require('../utils/parse-request')
6
- // const toPosix = require('../utils/to-posix')
7
- const addQuery = require('../utils/add-query')
8
- const parseComponent = require('../parser')
9
- const getJSONContent = require('../utils/get-json-content')
10
- const isUrlRequest = require('../utils/is-url-request')
11
-
12
- module.exports = function (jsonContent, options, rawCallback) {
13
- const mode = options.mode
14
- const env = options.env
15
- const defs = options.defs
16
- const loaderContext = options.loaderContext
17
- const resolveMode = options.resolveMode
18
- // const pagesMap = options.pagesMap
19
- const componentsMap = options.componentsMap
20
- const projectRoot = options.projectRoot
21
- const pathHash = options.pathHash
22
- const localPagesMap = {}
23
- const localComponentsMap = {}
24
- const buildInfo = loaderContext._module.buildInfo
25
-
26
- const output = '/* json */\n'
27
- let jsonObj = {}
28
- let tabBarMap
29
- let tabBarStr
30
- const context = loaderContext.context
31
-
32
- // const emitWarning = (msg) => {
33
- // loaderContext.emitWarning(
34
- // new Error('[json processor][' + loaderContext.resource + ']: ' + msg)
35
- // )
36
- // }
37
-
38
- // const emitError = (msg) => {
39
- // this.emitError(
40
- // new Error('[json compiler][' + this.resource + ']: ' + msg)
41
- // )
42
- // }
43
-
44
- // const stringifyRequest = r => loaderUtils.stringifyRequest(loaderContext, r)
45
-
46
- const callback = (err) => {
47
- return rawCallback(err, {
48
- output,
49
- jsonObj,
50
- localPagesMap,
51
- localComponentsMap,
52
- tabBarMap,
53
- tabBarStr
54
- })
55
- }
56
-
57
- if (!jsonContent) {
58
- return callback()
59
- }
60
- // 由于json需要提前读取在template处理中使用,src的场景已经在loader中处理了,此处无需考虑json.src的场景
61
- try {
62
- jsonObj = JSON5.parse(jsonContent)
63
- } catch (e) {
64
- return callback(e)
65
- }
66
-
67
- const fs = loaderContext._compiler.inputFileSystem
68
-
69
- const resolve = (context, request, callback) => {
70
- // const { queryObj } = parseRequest(request)
71
- // todo delete. parseRequest 不会返回 context 属性
72
- // context = queryObj.context || context
73
- return loaderContext.resolve(context, request, callback)
74
- }
75
-
76
- // const defaultTabbar = {
77
- // borderStyle: 'black',
78
- // position: 'bottom',
79
- // custom: false,
80
- // isShow: true
81
- // }
82
-
83
- // const processTabBar = (tabBar, callback) => {
84
- // if (tabBar) {
85
- // tabBar = Object.assign({}, defaultTabbar, tabBar)
86
- // tabBarMap = {}
87
- // jsonObj.tabBar.list.forEach(({ pagePath }) => {
88
- // tabBarMap[pagePath] = true
89
- // })
90
- // tabBarStr = JSON.stringify(tabBar)
91
- // tabBarStr = tabBarStr.replace(/"(iconPath|selectedIconPath)":"([^"]+)"/g, function (matched, $1, $2) {
92
- // if (isUrlRequest($2, projectRoot)) {
93
- // return `"${$1}":require(${stringifyRequest(loaderUtils.urlToRequest($2, projectRoot))})`
94
- // }
95
- // return matched
96
- // })
97
- // }
98
- // callback()
99
- // }
100
-
101
- const processPackages = (packages, context, callback) => {
102
- if (packages) {
103
- async.forEach(packages, (packagePath, callback) => {
104
- const parsed = parseRequest(packagePath)
105
- const queryObj = parsed.queryObj
106
- // readFile无法处理query
107
- packagePath = parsed.resourcePath
108
- async.waterfall([
109
- (callback) => {
110
- resolve(context, packagePath, (err, result) => {
111
- callback(err, result)
112
- })
113
- },
114
- (result, callback) => {
115
- loaderContext.addDependency(result)
116
- fs.readFile(result, (err, content) => {
117
- if (err) return callback(err)
118
- callback(err, result, content.toString('utf-8'))
119
- })
120
- },
121
- (result, content, callback) => {
122
- const filePath = result
123
- const extName = path.extname(filePath)
124
- if (extName === '.mpx' || extName === '.vue') {
125
- const parts = parseComponent(content, {
126
- filePath,
127
- needMap: loaderContext.sourceMap,
128
- mode,
129
- defs,
130
- env
131
- })
132
- getJSONContent(parts.json || {}, result, loaderContext, (err, content) => {
133
- callback(err, result, content)
134
- })
135
- } else {
136
- callback(null, result, content)
137
- }
138
- },
139
- (result, content, callback) => {
140
- try {
141
- content = JSON5.parse(content)
142
- } catch (err) {
143
- return callback(err)
144
- }
145
-
146
- const processSelfQueue = []
147
- const context = path.dirname(result)
148
-
149
- if (content.pages) {
150
- const tarRoot = queryObj.root
151
- if (tarRoot) {
152
- delete queryObj.root
153
- const subPackage = {
154
- tarRoot,
155
- pages: content.pages,
156
- ...queryObj
157
- }
158
- processSelfQueue.push((callback) => {
159
- processSubPackage(subPackage, context, callback)
160
- })
161
- } else {
162
- processSelfQueue.push((callback) => {
163
- processPages(content.pages, '', '', context, callback)
164
- })
165
- }
166
- }
167
- if (content.packages) {
168
- processSelfQueue.push((callback) => {
169
- processPackages(content.packages, context, callback)
170
- })
171
- }
172
- if (processSelfQueue.length) {
173
- async.parallel(processSelfQueue, callback)
174
- } else {
175
- callback()
176
- }
177
- }
178
- ], callback)
179
- }, callback)
180
- } else {
181
- callback()
182
- }
183
- }
184
-
185
- // const getPageName = (resourcePath, ext) => {
186
- // const baseName = path.basename(resourcePath, ext)
187
- // return path.join('pages', baseName + pathHash(resourcePath), baseName)
188
- // }
189
-
190
- const processPages = (pages, srcRoot = '', tarRoot = '', context, callback) => {
191
- if (pages) {
192
- context = path.join(context, srcRoot)
193
- async.forEach(pages, (page, callback) => {
194
- let pagePath = page
195
- if (typeof page !== 'string') {
196
- pagePath = page.src
197
- }
198
- // if (!isUrlRequest(page, projectRoot)) return callback()
199
- // if (resolveMode === 'native') {
200
- // page = loaderUtils.urlToRequest(page, projectRoot)
201
- // }
202
- // resolve(context, page, (err, resource) => {
203
- // if (err) return callback(err)
204
- // const { resourcePath, queryObj } = parseRequest(resource)
205
- // const ext = path.extname(resourcePath)
206
- // // 获取pageName
207
- // let pageName
208
- // if (aliasPath) {
209
- // pageName = toPosix(path.join(tarRoot, aliasPath))
210
- // // 判断 key 存在重复情况直接报错
211
- // for (let key in pagesMap) {
212
- // if (pagesMap[key] === pageName && key !== resourcePath) {
213
- // emitError(`Current page [${resourcePath}] registers a conflict page path [${pageName}] with existed page [${key}], which is not allowed, please rename it!`)
214
- // return callback()
215
- // }
216
- // }
217
- // } else {
218
- // const relative = path.relative(context, resourcePath)
219
- // if (/^\./.test(relative)) {
220
- // // 如果当前page不存在于context中,对其进行重命名
221
- // pageName = toPosix(path.join(tarRoot, getPageName(resourcePath, ext)))
222
- // emitWarning(`Current page [${resourcePath}] is not in current pages directory [${context}], the page path will be replaced with [${pageName}], use ?resolve to get the page path and navigate to it!`)
223
- // } else {
224
- // pageName = toPosix(path.join(tarRoot, /^(.*?)(\.[^.]*)?$/.exec(relative)[1]))
225
- // // 如果当前page与已有page存在命名冲突,也进行重命名
226
- // for (let key in pagesMap) {
227
- // // 此处引入pagesMap确保相同entry下路由路径重复注册才报错,不同entry下的路由路径重复则无影响
228
- // if (pagesMap[key] === pageName && key !== resourcePath && pagesMap[key] === loaderContext.resourcePath) {
229
- // const pageNameRaw = pageName
230
- // pageName = toPosix(path.join(tarRoot, getPageName(resourcePath, ext)))
231
- // emitWarning(`Current page [${resourcePath}] is registered with a conflict page path [${pageNameRaw}] which is already existed in system, the page path will be replaced with [${pageName}], use ?resolve to get the page path and navigate to it!`)
232
- // break
233
- // }
234
- // }
235
- // }
236
- // }
237
- // if (pagesMap[resourcePath]) {
238
- // emitWarning(`Current page [${resourcePath}] which is imported from [${loaderContext.resourcePath}] has been registered in pagesMap already, it will be ignored, please check it and remove the redundant page declaration!`)
239
- // return callback()
240
- // }
241
- // buildInfo.pagesMap = buildInfo.pagesMap || {}
242
- // buildInfo.pagesMap[resourcePath] = pagesMap[resourcePath] = pageName
243
- // pagesMap[resourcePath] = loaderContext.resourcePath
244
- localPagesMap[pagePath] = page
245
- // callback()
246
- // })
247
- callback()
248
- }, callback)
249
- } else {
250
- callback()
251
- }
252
- }
253
-
254
- const processSubPackage = (subPackage, context, callback) => {
255
- if (subPackage) {
256
- const tarRoot = subPackage.tarRoot || subPackage.root || ''
257
- const srcRoot = subPackage.srcRoot || subPackage.root || ''
258
- if (!tarRoot) return callback()
259
- processPages(subPackage.pages, srcRoot, tarRoot, context, callback)
260
- } else {
261
- callback()
262
- }
263
- }
264
-
265
- const processSubPackages = (subPackages, context, callback) => {
266
- if (subPackages) {
267
- async.forEach(subPackages, (subPackage, callback) => {
268
- processSubPackage(subPackage, context, callback)
269
- }, callback)
270
- } else {
271
- callback()
272
- }
273
- }
274
-
275
- const processComponents = (components, context, callback) => {
276
- if (components) {
277
- async.forEachOf(components, (component, name, callback) => {
278
- processComponent(component, name, context, callback)
279
- }, callback)
280
- } else {
281
- callback()
282
- }
283
- }
284
-
285
- const processComponent = (component, name, context, callback) => {
286
- if (!isUrlRequest(component, projectRoot)) return callback()
287
-
288
- if (resolveMode === 'native') {
289
- component = loaderUtils.urlToRequest(component, projectRoot)
290
- }
291
-
292
- resolve(context, component, (err, resource) => {
293
- if (err) return callback(err)
294
- const { resourcePath, queryObj } = parseRequest(resource)
295
- const parsed = path.parse(resourcePath)
296
- const componentId = parsed.name + pathHash(resourcePath)
297
-
298
- buildInfo.packageName = 'main'
299
- buildInfo.componentsMap = buildInfo.componentsMap || {}
300
- buildInfo.componentsMap[resourcePath] = componentsMap[resourcePath] = componentId
301
-
302
- localComponentsMap[name] = {
303
- resource: addQuery(resource, { isComponent: true, componentId }),
304
- async: queryObj.async
305
- }
306
- callback()
307
- })
308
- }
309
-
310
- // const processGenerics = (generics, context, callback) => {
311
- // if (generics) {
312
- // async.forEachOf(generics, (generic, name, callback) => {
313
- // if (generic.default) {
314
- // processComponent(generic.default, `${name}default`, context, callback)
315
- // } else {
316
- // callback()
317
- // }
318
- // }, callback)
319
- // } else {
320
- // callback()
321
- // }
322
- // }
323
-
324
- async.parallel([
325
- (callback) => {
326
- if (jsonObj.pages && jsonObj.pages[0]) {
327
- // 标记首页
328
- if (typeof jsonObj.pages[0] !== 'string') {
329
- jsonObj.pages[0].src = addQuery(jsonObj.pages[0].src, { isFirst: true })
330
- } else {
331
- jsonObj.pages[0] = addQuery(jsonObj.pages[0], { isFirst: true })
332
- }
333
- }
334
- processPages(jsonObj.pages, '', '', context, callback)
335
- },
336
- (callback) => {
337
- processComponents(jsonObj.usingComponents, context, callback)
338
- },
339
- (callback) => {
340
- processPackages(jsonObj.packages, context, callback)
341
- },
342
- (callback) => {
343
- processSubPackages(jsonObj.subPackages || jsonObj.subpackages, context, callback)
344
- }
345
- // (callback) => {
346
- // processGenerics(jsonObj.componentGenerics, context, callback)
347
- // },
348
- // (callback) => {
349
- // processTabBar(jsonObj.tabBar, callback)
350
- // }
351
- ], callback)
352
- }
@@ -1,203 +0,0 @@
1
- const genComponentTag = require('../utils/gen-component-tag')
2
- const loaderUtils = require('loader-utils')
3
- const normalize = require('../utils/normalize')
4
- const shallowStringify = require('../utils/shallow-stringify')
5
- const optionProcessorPath = normalize.lib('runtime/optionProcessor')
6
- const async = require('async')
7
- const createJSONHelper = require('../json-compiler/helper')
8
- const addQuery = require('../utils/add-query')
9
-
10
-
11
-
12
- const {
13
- buildComponentsMap,
14
- getRequireScript,
15
- buildGlobalParams,
16
- stringifyRequest
17
- } = require('./script-helper')
18
-
19
- module.exports = function (script, {
20
- loaderContext,
21
- ctorType,
22
- srcMode,
23
- moduleId,
24
- isProduction,
25
- componentGenerics,
26
- jsonConfig,
27
- outputPath,
28
- builtInComponentsMap,
29
- genericsInfo,
30
- wxsModuleMap,
31
- localComponentsMap,
32
- localPagesMap
33
- }, callback) {
34
- const { projectRoot, appInfo, webConfig } = loaderContext.getMpx()
35
-
36
-
37
- // add entry
38
- // const checkEntryDeps = (callback) => {
39
- // callback = callback || cacheCallback
40
- // if (callback && entryDeps.size === 0) {
41
- // callback()
42
- // } else {
43
- // cacheCallback = callback
44
- // }
45
- // }
46
-
47
- // const addEntryDep = (context, resource, name) => {
48
- // // 如果loader已经回调,就不再添加entry
49
- // if (callbacked) return
50
- // const dep = SingleEntryPlugin.createDependency(resource, name)
51
- // entryDeps.add(dep)
52
- // const virtualModule = new AddEntryDependency({
53
- // context: context._compiler.context,
54
- // dep,
55
- // name
56
- // })
57
- // /* eslint-disable camelcase */
58
- // context._module.__has_tenon_entry = true
59
- // context._module.addDependency(virtualModule)
60
- // entryDeps.delete(dep)
61
- // checkEntryDeps()
62
- // }
63
-
64
- const emitWarning = (msg) => {
65
- loaderContext.emitWarning(
66
- new Error('[tenon script processor][' + loaderContext.resource + ']: ' + msg)
67
- )
68
- }
69
-
70
- const emitError = (msg) => {
71
- loaderContext.emitError(
72
- new Error('[tenon script processor][' + loaderContext.resource + ']: ' + msg)
73
- )
74
- }
75
-
76
- const {
77
- processPage,
78
- processDynamicEntry
79
- } = createJSONHelper({
80
- loaderContext,
81
- emitWarning,
82
- emitError
83
- })
84
-
85
- // const { getRequire } = createHelpers(loaderContext)
86
-
87
- // const stringifyRequest = r => loaderUtils.stringifyRequest(loaderContext, r)
88
- // let tabBarPagesMap = {}
89
- // if (tabBar && tabBarMap) {
90
- // // 挂载tabBar组件
91
- // const tabBarRequest = stringifyRequest(addQuery(tabBar.custom ? './custom-tab-bar/index' : tabBarPath, { component: true }))
92
- // tabBarPagesMap['mpx-tab-bar'] = `getComponent(require(${tabBarRequest}))`
93
- // // 挂载tabBar页面
94
- // Object.keys(tabBarMap).forEach((pagePath) => {
95
- // const pageCfg = localPagesMap[pagePath]
96
- // if (pageCfg) {
97
- // const pageRequest = stringifyRequest(pageCfg.resource)
98
- // if (pageCfg.async) {
99
- // tabBarPagesMap[pagePath] = `()=>import(${pageRequest}).then(res => getComponent(res, { __mpxPageRoute: ${JSON.stringify(pagePath)} }))`
100
- // } else {
101
- // tabBarPagesMap[pagePath] = `getComponent(require(${pageRequest}), { __mpxPageRoute: ${JSON.stringify(pagePath)} })`
102
- // }
103
- // } else {
104
- // emitWarning(`TabBar page path ${pagePath} is not exist in local page map, please check!`)
105
- // }
106
- // })
107
- // }
108
-
109
- let output = '/* script */\n'
110
-
111
- let scriptSrcMode = srcMode
112
- if (script) {
113
- scriptSrcMode = script.mode || scriptSrcMode
114
- } else {
115
- script = {
116
- tag: 'script',
117
- content: ''
118
- }
119
- switch (ctorType) {
120
- case 'app':
121
- script.content = 'import {createApp} from "@mpxjs/core"\n' +
122
- 'createApp({})\n'
123
- break
124
- case 'page':
125
- script.content = 'import {createPage} from "@mpxjs/core"\n' +
126
- 'createPage({})\n'
127
- break
128
- case 'component':
129
- script.content = 'import {createComponent} from "@mpxjs/core"\n' +
130
- 'createComponent({})\n'
131
- }
132
- }
133
- output += genComponentTag(script, {
134
- attrs (script) {
135
- const attrs = Object.assign({}, script.attrs)
136
- // src改为内联require,删除
137
- delete attrs.src
138
- // script setup通过mpx处理,删除该属性避免vue报错
139
- delete attrs.setup
140
- return attrs
141
- },
142
- content (script) {
143
- let content = `\n import { processComponentOption, getComponent, getWxsMixin } from ${stringifyRequest(loaderContext, optionProcessorPath)}\n`
144
- let hasApp = true
145
- if (!appInfo.name) {
146
- hasApp = false
147
- }
148
-
149
-
150
- // 获取组件集合
151
- const componentsMap = buildComponentsMap({ localComponentsMap, builtInComponentsMap, loaderContext, jsonConfig })
152
-
153
- // 获取pageConfig
154
- const pageConfig = {}
155
- if (ctorType === 'page') {
156
- Object.assign(pageConfig, jsonConfig)
157
- delete pageConfig.usingComponents
158
- // content += `import * as Tenon from '@hummer/tenon-vue'\n`
159
- // content += `var page = require(${stringifyRequest(loaderContext, addQuery(loaderContext.resource, { page: true }))}).default\n`
160
- }
161
-
162
- content += buildGlobalParams({ moduleId, scriptSrcMode, loaderContext, isProduction, webConfig, hasApp })
163
- content += getRequireScript({ ctorType, script, loaderContext })
164
- content += `
165
- export default processComponentOption({
166
- option: global.__mpxOptionsMap[${JSON.stringify(moduleId)}],
167
- ctorType: ${JSON.stringify(ctorType)},
168
- outputPath: ${JSON.stringify(outputPath)},
169
- pageConfig: ${JSON.stringify(pageConfig)},
170
- // @ts-ignore
171
- componentsMap: ${shallowStringify(componentsMap)},
172
- componentGenerics: ${JSON.stringify(componentGenerics)},
173
- genericsInfo: ${JSON.stringify(genericsInfo)},
174
- wxsMixin: null,
175
- hasApp: ${hasApp}
176
- })\n`
177
-
178
- content += '\n__dynamic_page_slot__\n'
179
-
180
- return content
181
- }
182
- })
183
-
184
- output += '\n'
185
- // 处理pages
186
- const pageSet = new Set()
187
- let dynamicPageStr = ''
188
- async.each(localPagesMap, (pageCfg, callback) => {
189
- if (typeof pageCfg !== 'string') pageCfg.src = addQuery(pageCfg.src, { tenon: true })
190
- processPage(pageCfg, loaderContext.context, '', (err, entry, { key } = {}) => {
191
- if (err) return callback()
192
- if (pageSet.has(key)) return callback()
193
- pageSet.add(key)
194
- dynamicPageStr += `\n"${entry}"`
195
- callback()
196
- })
197
- }, () => {
198
- output = output.replace('__dynamic_page_slot__', processDynamicEntry(dynamicPageStr) || '')
199
- callback(null, {
200
- output
201
- })
202
- })
203
- }
@@ -1,21 +0,0 @@
1
- const genComponentTag = require('../utils/gen-component-tag')
2
-
3
- module.exports = function (styles, options, callback) {
4
- let output = '/* styles */\n'
5
- if (styles.length) {
6
- styles.forEach((style) => {
7
- output += genComponentTag(style, {
8
- attrs (style) {
9
- const attrs = Object.assign({}, style.attrs)
10
- if (options.autoScope) attrs.scoped = true
11
- return attrs
12
- }
13
- })
14
- output += '\n'
15
- })
16
- output += '\n'
17
- }
18
- callback(null, {
19
- output
20
- })
21
- }
@@ -1,126 +0,0 @@
1
- const templateCompiler = require('../template-compiler/compiler')
2
- const genComponentTag = require('../utils/gen-component-tag')
3
- const addQuery = require('../utils/add-query')
4
- const path = require('path')
5
- const parseRequest = require('../utils/parse-request')
6
-
7
-
8
- module.exports = function (template, {
9
- loaderContext,
10
- hasScoped,
11
- hasComment,
12
- isNative,
13
- srcMode,
14
- moduleId,
15
- ctorType,
16
- usingComponentsInfo,
17
- componentGenerics
18
- }, callback) {
19
- const mpx = loaderContext.getMpx()
20
- const {
21
- mode,
22
- env,
23
- defs,
24
- wxsContentMap,
25
- decodeHTMLText,
26
- externalClasses,
27
- checkUsingComponents,
28
- webConfig,
29
- autoVirtualHostRules
30
- } = mpx
31
- const { resourcePath } = parseRequest(loaderContext.resource)
32
- const builtInComponentsMap = {}
33
- let wxsModuleMap, genericsInfo
34
- let output = '/* template */\n'
35
-
36
- if (ctorType === 'app') {
37
- template = {
38
- tag: 'template',
39
- content: '<div class="app">this is app</div>'
40
- }
41
- }
42
-
43
- if (template) {
44
- // 由于远端src template资源引用的相对路径可能发生变化,暂时不支持。
45
- if (template.src) {
46
- return callback(new Error('[mpx loader][' + loaderContext.resource + ']: ' + 'template content must be inline in .mpx files!'))
47
- }
48
- if (template.lang) {
49
- return callback(new Error('[mpx loader][' + loaderContext.resource + ']: ' + 'template lang is not supported in trans web mode temporarily, we will support it in the future!'))
50
- }
51
-
52
- output += genComponentTag(template, (template) => {
53
- if (ctorType === 'app') {
54
- return template.content
55
- }
56
- if (template.content) {
57
- const templateSrcMode = template.mode || srcMode
58
- const parsed = templateCompiler.parse(template.content, {
59
- warn: (msg) => {
60
- loaderContext.emitWarning(
61
- new Error('[template compiler][' + loaderContext.resource + ']: ' + msg)
62
- )
63
- },
64
- error: (msg) => {
65
- loaderContext.emitError(
66
- new Error('[template compiler][' + loaderContext.resource + ']: ' + msg)
67
- )
68
- },
69
- usingComponentsInfo,
70
- hasComment,
71
- isNative,
72
- basename: path.basename(resourcePath),
73
- isComponent: ctorType === 'component',
74
- mode,
75
- srcMode: templateSrcMode,
76
- defs,
77
- decodeHTMLText,
78
- // externalClasses: options.externalClasses,
79
- hasScoped: false,
80
- moduleId,
81
- filePath: loaderContext.resourcePath,
82
- i18n: null,
83
- checkUsingComponents,
84
- // web模式下全局组件不会被合入usingComponents中,故globalComponents可以传空
85
- globalComponents: [],
86
- // web模式下实现抽象组件
87
- componentGenerics,
88
- })
89
- // if (parsed.meta.wxsModuleMap) {
90
- // wxsModuleMap = parsed.meta.wxsModuleMap
91
- // }
92
- // if (parsed.meta.wxsContentMap) {
93
- // for (let module in parsed.meta.wxsContentMap) {
94
- // wxsContentMap[`${resourcePath}~${module}`] = parsed.meta.wxsContentMap[module]
95
- // }
96
- // }
97
- if (parsed.meta.builtInComponentsMap) {
98
- Object.keys(parsed.meta.builtInComponentsMap).forEach((name) => {
99
- builtInComponentsMap[name] = {
100
- resource: addQuery(parsed.meta.builtInComponentsMap[name], { component: true })
101
- }
102
- })
103
- }
104
- // if (parsed.meta.genericsInfo) {
105
- // genericsInfo = parsed.meta.genericsInfo
106
- // }
107
- // 输出H5有多个root element时, 使用div标签包裹
108
- // if (parsed.root.tag === 'temp-node') {
109
- // const childLen = calculateRootEleChild(parsed.root.children)
110
- // if (childLen >= 2) {
111
- // parsed.root.tag = 'div'
112
- // }
113
- // }
114
- return templateCompiler.serialize(parsed.root)
115
- }
116
- })
117
- output += '\n\n'
118
- }
119
-
120
- callback(null, {
121
- output,
122
- builtInComponentsMap,
123
- genericsInfo,
124
- wxsModuleMap
125
- })
126
- }