@mpxjs/webpack-plugin 2.9.17 → 2.9.19-react.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.
Files changed (66) hide show
  1. package/lib/config.js +59 -97
  2. package/lib/dependencies/ResolveDependency.js +2 -2
  3. package/lib/helpers.js +5 -1
  4. package/lib/index.js +27 -19
  5. package/lib/loader.js +56 -118
  6. package/lib/native-loader.js +43 -20
  7. package/lib/platform/index.js +3 -0
  8. package/lib/platform/style/wx/index.js +413 -0
  9. package/lib/platform/template/wx/component-config/button.js +36 -0
  10. package/lib/platform/template/wx/component-config/cover-view.js +1 -1
  11. package/lib/platform/template/wx/component-config/image.js +15 -0
  12. package/lib/platform/template/wx/component-config/input.js +36 -0
  13. package/lib/platform/template/wx/component-config/scroll-view.js +27 -1
  14. package/lib/platform/template/wx/component-config/swiper-item.js +13 -1
  15. package/lib/platform/template/wx/component-config/swiper.js +25 -1
  16. package/lib/platform/template/wx/component-config/text.js +17 -1
  17. package/lib/platform/template/wx/component-config/textarea.js +39 -0
  18. package/lib/platform/template/wx/component-config/unsupported.js +18 -0
  19. package/lib/platform/template/wx/component-config/view.js +15 -1
  20. package/lib/platform/template/wx/index.js +89 -7
  21. package/lib/react/index.js +92 -0
  22. package/lib/react/processJSON.js +362 -0
  23. package/lib/react/processScript.js +40 -0
  24. package/lib/react/processStyles.js +63 -0
  25. package/lib/react/processTemplate.js +151 -0
  26. package/lib/react/script-helper.js +79 -0
  27. package/lib/react/style-helper.js +91 -0
  28. package/lib/runtime/components/react/event.config.ts +32 -0
  29. package/lib/runtime/components/react/getInnerListeners.ts +289 -0
  30. package/lib/runtime/components/react/getInnerListeners.type.ts +68 -0
  31. package/lib/runtime/components/react/mpx-button.tsx +402 -0
  32. package/lib/runtime/components/react/mpx-image/index.tsx +351 -0
  33. package/lib/runtime/components/react/mpx-image/svg.tsx +21 -0
  34. package/lib/runtime/components/react/mpx-input.tsx +389 -0
  35. package/lib/runtime/components/react/mpx-scroll-view.tsx +412 -0
  36. package/lib/runtime/components/react/mpx-swiper/carouse.tsx +407 -0
  37. package/lib/runtime/components/react/mpx-swiper/index.tsx +68 -0
  38. package/lib/runtime/components/react/mpx-swiper/type.ts +69 -0
  39. package/lib/runtime/components/react/mpx-swiper-item.tsx +42 -0
  40. package/lib/runtime/components/react/mpx-text.tsx +106 -0
  41. package/lib/runtime/components/react/mpx-textarea.tsx +46 -0
  42. package/lib/runtime/components/react/mpx-view.tsx +397 -0
  43. package/lib/runtime/components/react/utils.ts +92 -0
  44. package/lib/runtime/components/web/event.js +100 -0
  45. package/lib/runtime/components/web/getInnerListeners.js +0 -78
  46. package/lib/runtime/components/web/mpx-button.vue +1 -1
  47. package/lib/runtime/components/web/mpx-navigator.vue +1 -1
  48. package/lib/runtime/components/web/mpx-scroll-view.vue +113 -37
  49. package/lib/runtime/oc.wxs +16 -0
  50. package/lib/runtime/optionProcessor.js +1 -1
  51. package/lib/runtime/stringify.wxs +3 -7
  52. package/lib/runtime/useNodesRef.ts +39 -0
  53. package/lib/style-compiler/index.js +2 -1
  54. package/lib/template-compiler/compiler.js +544 -121
  55. package/lib/template-compiler/gen-node-react.js +95 -0
  56. package/lib/template-compiler/index.js +19 -31
  57. package/lib/utils/env.js +17 -0
  58. package/lib/utils/make-map.js +1 -1
  59. package/lib/utils/shallow-stringify.js +17 -0
  60. package/lib/utils/ts-loader-watch-run-loader-filter.js +4 -1
  61. package/lib/web/index.js +122 -0
  62. package/lib/web/processMainScript.js +6 -4
  63. package/lib/web/processScript.js +9 -5
  64. package/lib/web/processTemplate.js +14 -14
  65. package/lib/web/script-helper.js +11 -19
  66. package/package.json +7 -3
@@ -0,0 +1,95 @@
1
+ const isValidIdentifierStr = require('../utils/is-valid-identifier-str')
2
+
3
+ function genIf (node) {
4
+ node.ifProcessed = true
5
+ return genIfConditions(node.ifConditions.slice())
6
+ }
7
+
8
+ function genIfConditions (conditions) {
9
+ if (!conditions.length) return 'null'
10
+ const condition = conditions.shift()
11
+ if (condition.exp) {
12
+ return `(${condition.exp})?${genNode(condition.block)}:${genIfConditions(conditions)}`
13
+ } else {
14
+ return genNode(condition.block)
15
+ }
16
+ }
17
+
18
+ function genFor (node) {
19
+ node.forProcessed = true
20
+ const index = node.for.index || 'index'
21
+ const item = node.for.item || 'item'
22
+ return `_i(${node.for.exp}, function(${item},${index}){return ${genNode(node)}})`
23
+ }
24
+
25
+ const s = JSON.stringify
26
+
27
+ function mapAttrName (name) {
28
+ if (name === 'class') return 'className'
29
+ if (!isValidIdentifierStr(name)) return s(name)
30
+ return name
31
+ }
32
+
33
+ function genNode (node) {
34
+ let exp = ''
35
+ if (node) {
36
+ if (node.type === 3) {
37
+ if (!node.isComment) {
38
+ if (node.exps) {
39
+ exp += `${node.exps[0].exp}`
40
+ } else {
41
+ exp += `${s(node.text)}`
42
+ }
43
+ }
44
+ }
45
+ if (node.type === 1) {
46
+ if (node.tag !== 'temp-node') {
47
+ if (node.for && !node.forProcessed) {
48
+ exp += genFor(node)
49
+ } else if (node.if && !node.ifProcessed) {
50
+ exp += genIf(node)
51
+ } else {
52
+ const attrExpMap = (node.exps || []).reduce((map, { exp, attrName }) => {
53
+ if (attrName) {
54
+ map[attrName] = exp
55
+ }
56
+ return map
57
+ }, {})
58
+ if (node.slot) {
59
+ const name = node.slot.name
60
+ exp += `__getSlot(${name ? s(name) : ''})`
61
+ } else {
62
+ exp += `createElement(${node.isComponent || node.isBuiltIn ? `components[${node.is || s(node.tag)}]` : `getNativeComponent(${s(node.tag)})`}`
63
+ if (node.isRoot) {
64
+ exp += `, Object.assign({}, rootProps, {style: [${attrExpMap.style}, rootProps.style]})`
65
+ } else if (node.attrsList.length) {
66
+ const attrs = []
67
+ node.attrsList && node.attrsList.forEach(({ name, value }) => {
68
+ const attrExp = attrExpMap[name] ? attrExpMap[name] : s(value)
69
+ attrs.push(`${mapAttrName(name)}: ${attrExp}`)
70
+ })
71
+ exp += `, { ${attrs.join(', ')} }`
72
+ } else {
73
+ exp += ', null'
74
+ }
75
+
76
+ if (!node.unary && node.children.length) {
77
+ exp += ','
78
+ node.children.forEach(function (child, index) {
79
+ exp += `${index === 0 ? '' : ','}${genNode(child)}`
80
+ })
81
+ }
82
+ exp += ')'
83
+ }
84
+ }
85
+ } else {
86
+ node.children.forEach(function (child, index) {
87
+ exp += `${index === 0 ? '' : ','}${genNode(child)}`
88
+ })
89
+ }
90
+ }
91
+ }
92
+ return exp
93
+ }
94
+
95
+ module.exports = genNode
@@ -8,7 +8,7 @@ module.exports = function (raw) {
8
8
  this.cacheable()
9
9
  const { resourcePath, queryObj } = parseRequest(this.resource)
10
10
  const mpx = this.getMpx()
11
- const root = mpx.projectRoot
11
+ const projectRoot = mpx.projectRoot
12
12
  const mode = mpx.mode
13
13
  const env = mpx.env
14
14
  const defs = mpx.defs
@@ -17,15 +17,13 @@ module.exports = function (raw) {
17
17
  const decodeHTMLText = mpx.decodeHTMLText
18
18
  const globalSrcMode = mpx.srcMode
19
19
  const localSrcMode = queryObj.mode
20
- const packageName = queryObj.packageRoot || mpx.currentPackageRoot || 'main'
21
- const componentsMap = mpx.componentsMap[packageName]
22
- const pagesMap = mpx.pagesMap
23
20
  const wxsContentMap = mpx.wxsContentMap
24
21
  const optimizeRenderRules = mpx.optimizeRenderRules
25
22
  const usingComponents = queryObj.usingComponents || []
26
23
  const componentPlaceholder = queryObj.componentPlaceholder || []
27
24
  const hasComment = queryObj.hasComment
28
25
  const isNative = queryObj.isNative
26
+ const ctorType = queryObj.ctorType
29
27
  const hasScoped = queryObj.hasScoped
30
28
  const moduleId = queryObj.moduleId || 'm' + mpx.pathHash(resourcePath)
31
29
 
@@ -36,6 +34,7 @@ module.exports = function (raw) {
36
34
  break
37
35
  }
38
36
  }
37
+
39
38
  const warn = (msg) => {
40
39
  this.emitWarning(
41
40
  new Error('[template compiler][' + this.resource + ']: ' + msg)
@@ -48,15 +47,14 @@ module.exports = function (raw) {
48
47
  )
49
48
  }
50
49
 
51
- const { root: ast, meta } = compiler.parse(raw, {
50
+ const { root, meta } = compiler.parse(raw, {
52
51
  warn,
53
52
  error,
54
53
  usingComponents,
55
54
  componentPlaceholder,
56
55
  hasComment,
57
56
  isNative,
58
- isComponent: !!componentsMap[resourcePath],
59
- isPage: !!pagesMap[resourcePath],
57
+ ctorType,
60
58
  mode,
61
59
  env,
62
60
  srcMode: localSrcMode || globalSrcMode,
@@ -80,25 +78,23 @@ module.exports = function (raw) {
80
78
  }
81
79
  }
82
80
 
81
+ const result = compiler.serialize(root)
82
+ if (isNative) {
83
+ return result
84
+ }
85
+
83
86
  let resultSource = ''
84
87
 
85
88
  for (const module in meta.wxsModuleMap) {
86
- const src = loaderUtils.urlToRequest(meta.wxsModuleMap[module], root)
89
+ const src = loaderUtils.urlToRequest(meta.wxsModuleMap[module], projectRoot)
87
90
  resultSource += `var ${module} = require(${loaderUtils.stringifyRequest(this, src)});\n`
88
91
  }
89
92
 
90
- const result = compiler.serialize(ast)
91
-
92
- if (isNative) {
93
- return result
94
- }
95
-
96
- resultSource += `
97
- global.currentInject = {
93
+ resultSource += `global.currentInject = {
98
94
  moduleId: ${JSON.stringify(moduleId)}
99
95
  };\n`
100
96
 
101
- const rawCode = compiler.genNode(ast)
97
+ const rawCode = compiler.genNode(root)
102
98
  if (rawCode) {
103
99
  try {
104
100
  const ignoreMap = Object.assign({
@@ -116,8 +112,7 @@ global.currentInject = {
116
112
  renderReduce: optimizeRenderLevel === 1,
117
113
  ignoreMap
118
114
  })
119
- resultSource += `
120
- global.currentInject.render = function (_i, _c, _r, _sc) {
115
+ resultSource += `global.currentInject.render = function (_i, _c, _r, _sc) {
121
116
  ${bindResult.code}
122
117
  _r(${optimizeRenderLevel === 2 ? 'true' : ''});
123
118
  };\n`
@@ -125,10 +120,9 @@ _r(${optimizeRenderLevel === 2 ? 'true' : ''});
125
120
  resultSource += `global.currentInject.propKeys = ${JSON.stringify(bindResult.propKeys)};\n`
126
121
  }
127
122
  } catch (e) {
128
- error(`
129
- Invalid render function generated by the template, please check!\n
123
+ error(`Invalid render function generated by the template, please check!
130
124
  Template result:
131
- ${result}\n
125
+ ${result}
132
126
  Error code:
133
127
  ${rawCode}
134
128
  Error Detail:
@@ -138,21 +132,15 @@ ${e.stack}`)
138
132
  }
139
133
 
140
134
  if (meta.computed) {
141
- resultSource += bindThis.transform(`
142
- global.currentInject.injectComputed = {
143
- ${meta.computed.join(',')}
144
- };`).code + '\n'
135
+ resultSource += bindThis.transform(`global.currentInject.injectComputed = {${meta.computed.join(',')}};`).code + '\n'
145
136
  }
146
137
 
147
138
  if (meta.refs) {
148
- resultSource += `
149
- global.currentInject.getRefsData = function () {
150
- return ${JSON.stringify(meta.refs)};
151
- };\n`
139
+ resultSource += `global.currentInject.getRefsData = function () {return ${JSON.stringify(meta.refs)};};\n`
152
140
  }
153
141
 
154
142
  if (meta.options) {
155
- resultSource += `global.currentInject.injectOptions = ${JSON.stringify(meta.options)};` + '\n'
143
+ resultSource += `global.currentInject.injectOptions = ${JSON.stringify(meta.options)};\n`
156
144
  }
157
145
 
158
146
  this.emitFile(resourcePath, '', undefined, {
@@ -0,0 +1,17 @@
1
+ function isReact (mode) {
2
+ return mode === 'ios' || mode === 'android'
3
+ }
4
+
5
+ function isWeb (mode) {
6
+ return mode === 'web'
7
+ }
8
+
9
+ function isMiniProgram (mode) {
10
+ return !isWeb(mode) && !isReact(mode)
11
+ }
12
+
13
+ module.exports = {
14
+ isWeb,
15
+ isReact,
16
+ isMiniProgram
17
+ }
@@ -6,7 +6,7 @@ module.exports = function makeMap (str, expectsLowerCase) {
6
6
  const map = Object.create(null)
7
7
  const list = str.split(',')
8
8
  for (let i = 0; i < list.length; i++) {
9
- map[list[i]] = true
9
+ map[list[i].trim()] = true
10
10
  }
11
11
  return expectsLowerCase ? val => !!map[val.toLowerCase()] : val => !!map[val]
12
12
  }
@@ -0,0 +1,17 @@
1
+ const hasOwn = require('./has-own')
2
+
3
+ module.exports = function shallowStringify (obj, isTemplateExp) {
4
+ const arr = []
5
+ for (const key in obj) {
6
+ if (hasOwn(obj, key)) {
7
+ let value = obj[key]
8
+ if (Array.isArray(value)) {
9
+ value = `[${value.join(',')}]`
10
+ } else if (typeof value === 'object') {
11
+ value = shallowStringify(value, isTemplateExp)
12
+ }
13
+ arr.push(isTemplateExp ? `${key}:${value}` : `'${key}':${value}`)
14
+ }
15
+ }
16
+ return isTemplateExp ? `({${arr.join(',')}})` : `{${arr.join(',')}}`
17
+ }
@@ -1,7 +1,10 @@
1
+ const toPosix = require('./to-posix')
2
+
1
3
  module.exports = (loaders, loaderIndex) => {
2
4
  for (let i = loaderIndex; i >= 0; i--) {
3
5
  const currentLoader = loaders[i]
4
- if (currentLoader.path.endsWith('node_modules/ts-loader/dist/stringify-loader.js')) {
6
+ const currentLoaderPath = toPosix(currentLoader.path)
7
+ if (currentLoaderPath.endsWith('node_modules/ts-loader/dist/stringify-loader.js')) {
5
8
  return i
6
9
  }
7
10
  }
@@ -0,0 +1,122 @@
1
+ const async = require('async')
2
+ const processJSON = require('./processJSON')
3
+ const processMainScript = require('./processMainScript')
4
+ const processTemplate = require('./processTemplate')
5
+ const processStyles = require('./processStyles')
6
+ const processScript = require('./processScript')
7
+ const RecordVueContentDependency = require('../dependencies/RecordVueContentDependency')
8
+
9
+ module.exports = function ({
10
+ parts,
11
+ loaderContext,
12
+ pagesMap,
13
+ componentsMap,
14
+ queryObj,
15
+ ctorType,
16
+ srcMode,
17
+ moduleId,
18
+ isProduction,
19
+ hasScoped,
20
+ hasComment,
21
+ isNative,
22
+ usingComponents,
23
+ componentGenerics,
24
+ autoScope,
25
+ callback
26
+ }) {
27
+ const mpx = loaderContext.getMpx()
28
+ if (ctorType === 'app' && !queryObj.isApp) {
29
+ return async.waterfall([
30
+ (callback) => {
31
+ processJSON(parts.json, {
32
+ loaderContext,
33
+ pagesMap,
34
+ componentsMap
35
+ }, callback)
36
+ },
37
+ (jsonRes, callback) => {
38
+ processMainScript(parts.script, {
39
+ loaderContext,
40
+ ctorType,
41
+ srcMode,
42
+ moduleId,
43
+ isProduction,
44
+ jsonConfig: jsonRes.jsonObj,
45
+ outputPath: queryObj.outputPath || '',
46
+ localComponentsMap: jsonRes.localComponentsMap,
47
+ tabBar: jsonRes.jsonObj.tabBar,
48
+ tabBarMap: jsonRes.tabBarMap,
49
+ tabBarStr: jsonRes.tabBarStr,
50
+ localPagesMap: jsonRes.localPagesMap
51
+ }, callback)
52
+ }
53
+ ], (err, scriptRes) => {
54
+ if (err) return callback(err)
55
+ loaderContext.loaderIndex = -1
56
+ return callback(null, scriptRes.output)
57
+ })
58
+ }
59
+ // 通过RecordVueContentDependency和vueContentCache确保子request不再重复生成vueContent
60
+ const cacheContent = mpx.vueContentCache.get(loaderContext.resourcePath)
61
+ if (cacheContent) return callback(null, cacheContent)
62
+ let output = ''
63
+ return async.waterfall([
64
+ (callback) => {
65
+ async.parallel([
66
+ (callback) => {
67
+ processTemplate(parts.template, {
68
+ loaderContext,
69
+ hasScoped,
70
+ hasComment,
71
+ isNative,
72
+ srcMode,
73
+ moduleId,
74
+ ctorType,
75
+ usingComponents,
76
+ componentGenerics
77
+ }, callback)
78
+ },
79
+ (callback) => {
80
+ processStyles(parts.styles, {
81
+ ctorType,
82
+ autoScope,
83
+ moduleId
84
+ }, callback)
85
+ },
86
+ (callback) => {
87
+ processJSON(parts.json, {
88
+ loaderContext,
89
+ pagesMap,
90
+ componentsMap
91
+ }, callback)
92
+ }
93
+ ], (err, res) => {
94
+ callback(err, res)
95
+ })
96
+ },
97
+ ([templateRes, stylesRes, jsonRes], callback) => {
98
+ output += templateRes.output
99
+ output += stylesRes.output
100
+ output += jsonRes.output
101
+ processScript(parts.script, {
102
+ loaderContext,
103
+ ctorType,
104
+ srcMode,
105
+ moduleId,
106
+ isProduction,
107
+ componentGenerics,
108
+ jsonConfig: jsonRes.jsonObj,
109
+ outputPath: queryObj.outputPath || '',
110
+ builtInComponentsMap: templateRes.builtInComponentsMap,
111
+ genericsInfo: templateRes.genericsInfo,
112
+ wxsModuleMap: templateRes.wxsModuleMap,
113
+ localComponentsMap: jsonRes.localComponentsMap
114
+ }, callback)
115
+ }
116
+ ], (err, scriptRes) => {
117
+ if (err) return callback(err)
118
+ output += scriptRes.output
119
+ loaderContext._module.addPresentationalDependency(new RecordVueContentDependency(loaderContext.resourcePath, output))
120
+ callback(null, output)
121
+ })
122
+ }
@@ -1,12 +1,13 @@
1
1
  // 该文件下的字符串语句需要使用 es5 语法
2
2
  const addQuery = require('../utils/add-query')
3
3
  const normalize = require('../utils/normalize')
4
+ const shallowStringify = require('../utils/shallow-stringify')
4
5
  const optionProcessorPath = normalize.lib('runtime/optionProcessor')
6
+ const eventPath = normalize.lib('runtime/components/web/event')
5
7
  const {
6
8
  buildComponentsMap,
7
9
  buildPagesMap,
8
10
  buildGlobalParams,
9
- shallowStringify,
10
11
  stringifyRequest,
11
12
  buildI18n
12
13
  } = require('./script-helper')
@@ -22,8 +23,7 @@ module.exports = function (script, {
22
23
  tabBar,
23
24
  tabBarMap,
24
25
  tabBarStr,
25
- localPagesMap,
26
- resource
26
+ localPagesMap
27
27
  }, callback) {
28
28
  const { i18n, webConfig, hasUnoCSS } = loaderContext.getMpx()
29
29
  const { pagesMap, firstPage, globalTabBar } = buildPagesMap({
@@ -65,7 +65,9 @@ module.exports = function (script, {
65
65
  globalTabBar
66
66
  })
67
67
 
68
- output += `\n var App = require(${stringifyRequest(loaderContext, addQuery(resource, { isApp: true }))}).default\n`
68
+ output += `\n require(${stringifyRequest(loaderContext, eventPath)})\n`
69
+
70
+ output += `\n var App = require(${stringifyRequest(loaderContext, addQuery(loaderContext.resource, { isApp: true }))}).default\n`
69
71
 
70
72
  output += `
71
73
  export default processAppOption({
@@ -1,8 +1,14 @@
1
1
  const genComponentTag = require('../utils/gen-component-tag')
2
2
  const loaderUtils = require('loader-utils')
3
3
  const normalize = require('../utils/normalize')
4
+ const shallowStringify = require('../utils/shallow-stringify')
4
5
  const optionProcessorPath = normalize.lib('runtime/optionProcessor')
5
- const { buildComponentsMap, getRequireScript, buildGlobalParams, shallowStringify } = require('./script-helper')
6
+ const {
7
+ buildComponentsMap,
8
+ getRequireScript,
9
+ buildGlobalParams,
10
+ stringifyRequest
11
+ } = require('./script-helper')
6
12
 
7
13
  module.exports = function (script, {
8
14
  loaderContext,
@@ -20,8 +26,6 @@ module.exports = function (script, {
20
26
  }, callback) {
21
27
  const { projectRoot, appInfo } = loaderContext.getMpx()
22
28
 
23
- const stringifyRequest = r => loaderUtils.stringifyRequest(loaderContext, r)
24
-
25
29
  let output = '/* script */\n'
26
30
 
27
31
  let scriptSrcMode = srcMode
@@ -40,7 +44,7 @@ module.exports = function (script, {
40
44
  return attrs
41
45
  },
42
46
  content (script) {
43
- let content = `\n import { processComponentOption, getComponent, getWxsMixin } from ${stringifyRequest(optionProcessorPath)}\n`
47
+ let content = `\n import { processComponentOption, getComponent, getWxsMixin } from ${stringifyRequest(loaderContext, optionProcessorPath)}\n`
44
48
  let hasApp = true
45
49
  if (!appInfo.name) {
46
50
  hasApp = false
@@ -50,7 +54,7 @@ module.exports = function (script, {
50
54
  if (wxsModuleMap) {
51
55
  Object.keys(wxsModuleMap).forEach((module) => {
52
56
  const src = loaderUtils.urlToRequest(wxsModuleMap[module], projectRoot)
53
- const expression = `require(${stringifyRequest(src)})`
57
+ const expression = `require(${stringifyRequest(loaderContext, src)})`
54
58
  content += ` wxsModules.${module} = ${expression}\n`
55
59
  })
56
60
  }
@@ -59,23 +59,23 @@ module.exports = function (template, {
59
59
  }
60
60
  if (template.content) {
61
61
  const templateSrcMode = template.mode || srcMode
62
-
62
+ const warn = (msg) => {
63
+ loaderContext.emitWarning(
64
+ new Error('[template compiler][' + loaderContext.resource + ']: ' + msg)
65
+ )
66
+ }
67
+ const error = (msg) => {
68
+ loaderContext.emitError(
69
+ new Error('[template compiler][' + loaderContext.resource + ']: ' + msg)
70
+ )
71
+ }
63
72
  const { root, meta } = templateCompiler.parse(template.content, {
64
- warn: (msg) => {
65
- loaderContext.emitWarning(
66
- new Error('[template compiler][' + loaderContext.resource + ']: ' + msg)
67
- )
68
- },
69
- error: (msg) => {
70
- loaderContext.emitError(
71
- new Error('[template compiler][' + loaderContext.resource + ']: ' + msg)
72
- )
73
- },
73
+ warn,
74
+ error,
74
75
  usingComponents,
75
76
  hasComment,
76
77
  isNative,
77
- isComponent: ctorType === 'component',
78
- isPage: ctorType === 'page',
78
+ ctorType,
79
79
  mode,
80
80
  srcMode: templateSrcMode,
81
81
  defs,
@@ -114,7 +114,7 @@ module.exports = function (template, {
114
114
  return templateCompiler.serialize(root)
115
115
  }
116
116
  })
117
- output += '\n\n'
117
+ output += '\n'
118
118
  }
119
119
 
120
120
  callback(null, {
@@ -1,29 +1,16 @@
1
- const hasOwn = require('../utils/has-own')
2
1
  const loaderUtils = require('loader-utils')
3
2
  const normalize = require('../utils/normalize')
4
3
  const createHelpers = require('../helpers')
5
4
  const tabBarContainerPath = normalize.lib('runtime/components/web/mpx-tab-bar-container.vue')
6
5
  const tabBarPath = normalize.lib('runtime/components/web/mpx-tab-bar.vue')
7
6
  const addQuery = require('../utils/add-query')
7
+ const parseRequest = require('../utils/parse-request')
8
+ const shallowStringify = require('../utils/shallow-stringify')
8
9
 
9
10
  function stringifyRequest (loaderContext, request) {
10
11
  return loaderUtils.stringifyRequest(loaderContext, request)
11
12
  }
12
13
 
13
- function shallowStringify (obj) {
14
- const arr = []
15
- for (const key in obj) {
16
- if (hasOwn(obj, key)) {
17
- let value = obj[key]
18
- if (Array.isArray(value)) {
19
- value = `[${value.join(',')}]`
20
- }
21
- arr.push(`'${key}':${value}`)
22
- }
23
- }
24
- return `{${arr.join(',')}}`
25
- }
26
-
27
14
  function getAsyncChunkName (chunkName) {
28
15
  if (chunkName && typeof chunkName !== 'boolean') {
29
16
  return `/* webpackChunkName: "${chunkName}" */`
@@ -128,10 +115,17 @@ function buildPagesMap ({ localPagesMap, loaderContext, tabBar, tabBarMap, tabBa
128
115
  }
129
116
  }
130
117
 
131
- function getRequireScript ({ ctorType, script, loaderContext }) {
118
+ function getRequireScript ({ script, ctorType, loaderContext }) {
132
119
  let content = ' /** script content **/\n'
133
- const extraOptions = { ctorType, lang: script.lang || 'js' }
134
120
  const { getRequire } = createHelpers(loaderContext)
121
+ const { resourcePath, queryObj } = parseRequest(loaderContext.resource)
122
+ const extraOptions = {
123
+ ...script.src
124
+ ? { ...queryObj, resourcePath }
125
+ : null,
126
+ ctorType,
127
+ lang: script.lang || 'js'
128
+ }
135
129
  content += ` ${getRequire('script', script, extraOptions)}\n`
136
130
  return content
137
131
  }
@@ -217,8 +211,6 @@ module.exports = {
217
211
  buildComponentsMap,
218
212
  getRequireScript,
219
213
  buildGlobalParams,
220
- shallowStringify,
221
- getAsyncChunkName,
222
214
  stringifyRequest,
223
215
  buildI18n
224
216
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.9.17",
3
+ "version": "2.9.19-react.0",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"
@@ -78,10 +78,14 @@
78
78
  },
79
79
  "devDependencies": {
80
80
  "@types/babel-traverse": "^6.25.4",
81
- "@types/babel-types": "^7.0.4"
81
+ "@types/babel-types": "^7.0.4",
82
+ "@types/react": "^18.2.79",
83
+ "react": "^18.2.0",
84
+ "react-native": "^0.74.0",
85
+ "react-native-svg": "^15.2.0"
82
86
  },
83
87
  "engines": {
84
88
  "node": ">=14.14.0"
85
89
  },
86
- "gitHead": "80dd826352ab7178952f6ac1f2d7dbcf610fe6cf"
90
+ "gitHead": "a09ab1b994eaf20b1772491709580fe75499e688"
87
91
  }