@mpxjs/webpack-plugin 2.6.114-alpha.6 → 2.6.114-alpha.9

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 (100) hide show
  1. package/lib/{dependency → dependencies}/AddEntryDependency.js +0 -0
  2. package/lib/dependencies/AppEntryDependency.js +58 -0
  3. package/lib/dependencies/CommonJsAsyncDependency.js +51 -0
  4. package/lib/dependencies/CommonJsVariableDependency.js +81 -0
  5. package/lib/dependencies/DynamicEntryDependency.js +171 -0
  6. package/lib/dependencies/FlagPluginDependency.js +24 -0
  7. package/lib/dependencies/InjectDependency.js +43 -0
  8. package/lib/dependencies/RecordGlobalComponentsDependency.js +50 -0
  9. package/lib/dependencies/RecordIndependentDependency.js +44 -0
  10. package/lib/dependencies/RecordResourceMapDependency.js +62 -0
  11. package/lib/dependencies/RemoveEntryDependency.js +40 -0
  12. package/lib/{dependency → dependencies}/ReplaceDependency.js +19 -2
  13. package/lib/dependencies/ResolveDependency.js +88 -0
  14. package/lib/extractor.js +82 -178
  15. package/lib/file-loader.js +7 -19
  16. package/lib/helpers.js +39 -334
  17. package/lib/independent-loader.js +52 -0
  18. package/lib/index.js +854 -542
  19. package/lib/json-compiler/helper.js +156 -0
  20. package/lib/json-compiler/index.js +242 -451
  21. package/lib/json-compiler/plugin.js +150 -0
  22. package/lib/json-compiler/{theme-loader.js → theme.js} +5 -3
  23. package/lib/loader.js +137 -240
  24. package/lib/native-loader.js +71 -133
  25. package/lib/parser.js +1 -2
  26. package/lib/partial-compile/index.js +35 -0
  27. package/lib/platform/json/wx/index.js +1 -1
  28. package/lib/platform/template/normalize-component-rules.js +2 -3
  29. package/lib/platform/template/wx/index.js +30 -4
  30. package/lib/record-loader.js +11 -0
  31. package/lib/{path-loader.js → resolve-loader.js} +0 -0
  32. package/lib/resolver/AddEnvPlugin.js +4 -3
  33. package/lib/resolver/AddModePlugin.js +4 -3
  34. package/lib/resolver/FixDescriptionInfoPlugin.js +28 -0
  35. package/lib/resolver/PackageEntryPlugin.js +23 -36
  36. package/lib/runtime/base.styl +5 -0
  37. package/lib/runtime/components/web/mpx-image.vue +20 -5
  38. package/lib/runtime/components/web/mpx-movable-view.vue +6 -2
  39. package/lib/runtime/components/web/mpx-swiper.vue +18 -3
  40. package/lib/runtime/i18n.wxs +31 -11
  41. package/lib/runtime/optionProcessor.js +48 -3
  42. package/lib/selector.js +29 -10
  43. package/lib/style-compiler/index.js +15 -23
  44. package/lib/style-compiler/load-postcss-config.js +3 -1
  45. package/lib/style-compiler/plugins/conditional-strip.js +68 -65
  46. package/lib/style-compiler/plugins/rpx.js +43 -37
  47. package/lib/style-compiler/plugins/scope-id.js +79 -72
  48. package/lib/style-compiler/plugins/trans-special.js +25 -18
  49. package/lib/style-compiler/plugins/trim.js +13 -7
  50. package/lib/style-compiler/plugins/vw.js +22 -16
  51. package/lib/template-compiler/compiler.js +95 -197
  52. package/lib/template-compiler/index.js +52 -139
  53. package/lib/template-compiler/trans-dynamic-class-expr.js +18 -13
  54. package/lib/tenon/index.js +1 -4
  55. package/lib/tenon/processJSON.js +71 -76
  56. package/lib/tenon/processScript.js +60 -59
  57. package/lib/url-loader.js +11 -29
  58. package/lib/utils/add-query.js +1 -1
  59. package/lib/utils/const.js +10 -0
  60. package/lib/utils/emit-file.js +10 -0
  61. package/lib/utils/eval-json-js.js +31 -0
  62. package/lib/utils/get-entry-name.js +13 -0
  63. package/lib/utils/get-json-content.js +42 -0
  64. package/lib/utils/get-relative-path.js +2 -1
  65. package/lib/utils/is-url-request.js +10 -1
  66. package/lib/utils/match-condition.js +4 -1
  67. package/lib/utils/normalize.js +4 -15
  68. package/lib/utils/parse-request.js +3 -3
  69. package/lib/utils/resolve.js +13 -0
  70. package/lib/utils/set.js +47 -0
  71. package/lib/utils/stringify-loaders-resource.js +25 -0
  72. package/lib/utils/stringify-query.js +4 -0
  73. package/lib/web/processJSON.js +113 -144
  74. package/lib/web/processScript.js +47 -34
  75. package/lib/web/processTemplate.js +57 -40
  76. package/lib/wxml/{wxml-loader.js → loader.js} +21 -62
  77. package/lib/wxs/WxsModuleIdsPlugin.js +29 -0
  78. package/lib/wxs/WxsParserPlugin.js +2 -2
  79. package/lib/wxs/WxsPlugin.js +4 -8
  80. package/lib/wxs/WxsTemplatePlugin.js +46 -92
  81. package/lib/wxs/{wxs-i18n-loader.js → i18n-loader.js} +5 -4
  82. package/lib/wxs/loader.js +142 -0
  83. package/lib/wxs/{wxs-pre-loader.js → pre-loader.js} +20 -5
  84. package/lib/wxss/loader.js +31 -43
  85. package/lib/wxss/localsLoader.js +1 -5
  86. package/lib/wxss/processCss.js +107 -103
  87. package/package.json +18 -20
  88. package/lib/built-in-loader.js +0 -49
  89. package/lib/content-loader.js +0 -13
  90. package/lib/dependency/ChildCompileDependency.js +0 -24
  91. package/lib/dependency/InjectDependency.js +0 -26
  92. package/lib/dependency/RemovedModuleDependency.js +0 -23
  93. package/lib/dependency/ResolveDependency.js +0 -53
  94. package/lib/plugin-loader.js +0 -287
  95. package/lib/staticConfig.js +0 -4
  96. package/lib/utils/get-main-compilation.js +0 -6
  97. package/lib/utils/read-json-for-src.js +0 -34
  98. package/lib/utils/try-require.js +0 -16
  99. package/lib/wxs/wxs-loader.js +0 -117
  100. package/lib/wxss/getImportPrefix.js +0 -30
@@ -1,19 +1,14 @@
1
1
  const compiler = require('./compiler')
2
- const loaderUtils = require('loader-utils')
3
2
  const bindThis = require('./bind-this').transform
4
- const InjectDependency = require('../dependency/InjectDependency')
5
3
  const parseRequest = require('../utils/parse-request')
6
- const getMainCompilation = require('../utils/get-main-compilation')
7
- const matchCondition = require('../utils/match-condition')
8
- const path = require('path')
4
+ const { matchCondition } = require('../utils/match-condition')
5
+ const loaderUtils = require('loader-utils')
9
6
 
10
7
  module.exports = function (raw) {
11
8
  this.cacheable()
12
- const options = loaderUtils.getOptions(this) || {}
13
9
  const { resourcePath, queryObj } = parseRequest(this.resource)
14
- const compilation = this._compilation
15
- const mainCompilation = getMainCompilation(compilation)
16
- const mpx = mainCompilation.__mpx__
10
+ const mpx = this.getMpx()
11
+ const root = mpx.projectRoot
17
12
  const mode = mpx.mode
18
13
  const env = mpx.env
19
14
  const defs = mpx.defs
@@ -25,6 +20,11 @@ module.exports = function (raw) {
25
20
  const packageName = queryObj.packageRoot || mpx.currentPackageRoot || 'main'
26
21
  const componentsMap = mpx.componentsMap[packageName]
27
22
  const wxsContentMap = mpx.wxsContentMap
23
+ const usingComponents = queryObj.usingComponents || []
24
+ const hasComment = queryObj.hasComment
25
+ const isNative = queryObj.isNative
26
+ const hasScoped = queryObj.hasScoped
27
+ const moduleId = queryObj.moduleId || 'm' + mpx.pathHash(resourcePath)
28
28
 
29
29
  const warn = (msg) => {
30
30
  this.emitWarning(
@@ -38,13 +38,12 @@ module.exports = function (raw) {
38
38
  )
39
39
  }
40
40
 
41
- const parsed = compiler.parse(raw, {
41
+ const { root: ast, meta } = compiler.parse(raw, {
42
42
  warn,
43
43
  error,
44
- usingComponents: options.usingComponents,
45
- hasComment: options.hasComment,
46
- isNative: options.isNative,
47
- basename: path.basename(resourcePath),
44
+ usingComponents,
45
+ hasComment,
46
+ isNative,
48
47
  isComponent: !!componentsMap[resourcePath],
49
48
  mode,
50
49
  env,
@@ -52,49 +51,56 @@ module.exports = function (raw) {
52
51
  defs,
53
52
  decodeHTMLText,
54
53
  externalClasses,
55
- hasScoped: options.hasScoped,
56
- moduleId: options.moduleId,
57
- filePath: this.resourcePath,
54
+ hasScoped,
55
+ moduleId,
56
+ // 这里需传递resourcePath和wxsContentMap保持一致
57
+ filePath: resourcePath,
58
58
  i18n,
59
59
  checkUsingComponents: mpx.checkUsingComponents,
60
60
  globalComponents: Object.keys(mpx.usingComponents),
61
- // deprecated option
62
- globalMpxAttrsFilter: mpx.globalMpxAttrsFilter,
63
- forceProxyEvent: matchCondition(this.resourcePath, mpx.forceProxyEventRules),
64
- hasVirtualHost: matchCondition(resourcePath, mpx.autoVirtualHostRules)
61
+ forceProxyEvent: matchCondition(resourcePath, mpx.forceProxyEventRules),
62
+ hasVirtualHost: matchCondition(resourcePath, mpx.autoVirtualHostRules),
63
+ proxyComponentEventsRules: mpx.proxyComponentEventsRules
65
64
  })
66
65
 
67
- let ast = parsed.root
68
- let meta = parsed.meta
69
-
70
66
  if (meta.wxsContentMap) {
71
67
  for (let module in meta.wxsContentMap) {
72
68
  wxsContentMap[`${resourcePath}~${module}`] = meta.wxsContentMap[module]
73
69
  }
74
70
  }
75
71
 
72
+ let resultSource = ''
73
+
74
+ for (let module in meta.wxsModuleMap) {
75
+ const src = loaderUtils.urlToRequest(meta.wxsModuleMap[module], root)
76
+ resultSource += `var ${module} = require(${loaderUtils.stringifyRequest(this, src)});\n`
77
+ }
78
+
76
79
  let result = compiler.serialize(ast)
77
80
 
78
- if (options.isNative || mpx.forceDisableInject) {
81
+ if (isNative) {
79
82
  return result
80
83
  }
81
84
 
82
- const rawCode = `global.currentInject = {
83
- moduleId: ${JSON.stringify(options.moduleId)},
84
- render: function () {
85
- ${compiler.genNode(ast)}this._r();
86
- }
85
+ const rawCode = `
86
+ global.currentInject = {
87
+ moduleId: ${JSON.stringify(moduleId)},
88
+ render: function () {
89
+ ${compiler.genNode(ast)}
90
+ this._r();
91
+ }
87
92
  };\n`
88
93
 
89
- let renderResult
94
+ let bindResult
90
95
 
91
96
  try {
92
- renderResult = bindThis(rawCode, {
97
+ bindResult = bindThis(rawCode, {
93
98
  needCollect: true,
94
99
  ignoreMap: meta.wxsModuleMap
95
100
  })
96
101
  } catch (e) {
97
- error(`Invalid render function generated by the template, please check!\n
102
+ error(`
103
+ Invalid render function generated by the template, please check!\n
98
104
  Template result:
99
105
  ${result}\n
100
106
  Error code:
@@ -104,123 +110,30 @@ ${e.stack}`)
104
110
  return result
105
111
  }
106
112
 
107
- // todo 此处在loader中往其他模块addDep更加危险,考虑修改为通过抽取后的空模块的module.exports来传递信息
108
- let globalInjectCode = renderResult.code + '\n'
113
+ resultSource += bindResult.code + '\n'
109
114
 
110
- if ((mode === 'tt' || mode === 'swan') && renderResult.propKeys) {
111
- globalInjectCode += `global.currentInject.propKeys = ${JSON.stringify(renderResult.propKeys)};\n`
115
+ if ((mode === 'tt' || mode === 'swan') && bindResult.propKeys) {
116
+ resultSource += `global.currentInject.propKeys = ${JSON.stringify(bindResult.propKeys)};\n`
112
117
  }
113
118
 
114
119
  if (meta.computed) {
115
- globalInjectCode += bindThis(`global.currentInject.injectComputed = {
120
+ resultSource += bindThis(`
121
+ global.currentInject.injectComputed = {
116
122
  ${meta.computed.join(',')}
117
- };`).code + '\n'
123
+ };`).code + '\n'
118
124
  }
119
125
 
120
126
  if (meta.refs) {
121
- globalInjectCode += `global.currentInject.getRefsData = function () {
127
+ resultSource += `
128
+ global.currentInject.getRefsData = function () {
122
129
  return ${JSON.stringify(meta.refs)};
123
- };\n`
124
- }
125
-
126
- if (meta.options) {
127
- globalInjectCode += bindThis(`global.currentInject.injectOptions = ${JSON.stringify(meta.options)};`).code + '\n'
130
+ };\n`
128
131
  }
129
132
 
130
- const issuer = this._module.issuer
131
- const parser = issuer.parser
132
-
133
- // 同步issuer的dependencies,确保watch中issuer rebuild时template也进行rebuild,使该loader中往issuer中注入的依赖持续有效
134
- issuer.buildInfo.fileDependencies.forEach((dep) => {
135
- this.addDependency(dep)
136
- })
137
- issuer.buildInfo.contextDependencies.forEach((dep) => {
138
- this.addContextDependency(dep)
139
- })
140
-
141
- // 删除issuer中上次注入的dependencies,避免issuer本身不需要更新时上次的注入代码残留
142
- issuer.dependencies = issuer.dependencies.filter((dep) => {
143
- return !dep.templateInject
144
- })
145
-
146
- const dep = new InjectDependency({
147
- content: globalInjectCode,
148
- index: -2
133
+ this.emitFile(resourcePath, '', undefined, {
134
+ skipEmit: true,
135
+ extractedResultSource: resultSource
149
136
  })
150
137
 
151
- dep.templateInject = true
152
- issuer.addDependency(dep)
153
-
154
- let isSync = true
155
-
156
- const iterationOfArrayCallback = (arr, fn) => {
157
- for (let index = 0; index < arr.length; index++) {
158
- fn(arr[index])
159
- }
160
- }
161
-
162
- const dependencies = new Map()
163
-
164
- const addDependency = dep => {
165
- const resourceIdent = dep.getResourceIdentifier()
166
- if (resourceIdent) {
167
- const factory = compilation.dependencyFactories.get(dep.constructor)
168
- if (factory === undefined) {
169
- throw new Error(`No module factory available for dependency type: ${dep.constructor.name}`)
170
- }
171
- let innerMap = dependencies.get(factory)
172
- if (innerMap === undefined) {
173
- dependencies.set(factory, (innerMap = new Map()))
174
- }
175
- let list = innerMap.get(resourceIdent)
176
- if (list === undefined) innerMap.set(resourceIdent, (list = []))
177
- list.push(dep)
178
- }
179
- }
180
-
181
- for (let module in meta.wxsModuleMap) {
182
- isSync = false
183
- const src = loaderUtils.urlToRequest(meta.wxsModuleMap[module], options.root)
184
- // 编译render函数只在mpx文件中运行,此处issuer的context一定等同于当前loader的context
185
- const expression = `require(${loaderUtils.stringifyRequest(this, src)})`
186
- const deps = []
187
- parser.parse(expression, {
188
- current: {
189
- addDependency: dep => {
190
- dep.userRequest = module
191
- deps.push(dep)
192
- }
193
- },
194
- module: issuer
195
- })
196
- issuer.addVariable(module, expression, deps)
197
- iterationOfArrayCallback(deps, addDependency)
198
- }
199
-
200
- if (isSync) {
201
- return result
202
- } else {
203
- const callback = this.async()
204
-
205
- const sortedDependencies = []
206
- for (const pair1 of dependencies) {
207
- for (const pair2 of pair1[1]) {
208
- sortedDependencies.push({
209
- factory: pair1[0],
210
- dependencies: pair2[1]
211
- })
212
- }
213
- }
214
-
215
- compilation.addModuleDependencies(
216
- issuer,
217
- sortedDependencies,
218
- compilation.bail,
219
- null,
220
- true,
221
- () => {
222
- callback(null, result)
223
- }
224
- )
225
- }
138
+ return result
226
139
  }
@@ -1,29 +1,34 @@
1
1
  const babylon = require('@babel/parser')
2
2
  const t = require('@babel/types')
3
+ const traverse = require('@babel/traverse').default
3
4
  const generate = require('@babel/generator').default
4
5
 
5
6
  module.exports = function transDynamicClassExpr (expr, { error } = {}) {
6
7
  try {
7
- const ast = babylon.parseExpression(expr, {
8
+ const ast = babylon.parse(expr, {
8
9
  plugins: [
9
10
  'objectRestSpread'
10
11
  ]
11
12
  })
12
- if (t.isObjectExpression(ast)) {
13
- ast.properties.forEach((property) => {
14
- if (t.isObjectProperty(property) && !property.computed) {
15
- const propertyName = property.key.name || property.key.value
16
- if (/-/.test(propertyName)) {
17
- if (/\$/.test(propertyName)) {
18
- error && error(`Dynamic classname [${propertyName}] is not supported, which includes [-] char and [$] char at the same time.`)
13
+ traverse(ast, {
14
+ ObjectExpression (path) {
15
+ path.node.properties.forEach((property) => {
16
+ if (t.isObjectProperty(property) && !property.computed) {
17
+ const propertyName = property.key.name || property.key.value
18
+ if (/-/.test(propertyName)) {
19
+ if (/\$/.test(propertyName)) {
20
+ error && error(`Dynamic classname [${propertyName}] is not supported, which includes [-] char and [$] char at the same time.`)
21
+ } else {
22
+ property.key = t.identifier(propertyName.replace(/-/g, '$$') + 'MpxDash')
23
+ }
19
24
  } else {
20
- property.key = t.identifier(propertyName.replace(/-/g, '$$') + 'MpxDash')
25
+ property.key = t.identifier(propertyName)
21
26
  }
22
27
  }
23
- }
24
- })
25
- }
26
- return generate(ast, {
28
+ })
29
+ }
30
+ })
31
+ return generate(ast.program.body[0].expression, {
27
32
  compact: true
28
33
  }).code
29
34
  } catch (e) {
@@ -15,8 +15,6 @@ module.exports = function ({
15
15
  queryObj,
16
16
  autoScope,
17
17
  componentsMap,
18
- projectRoot,
19
- getRequireForSrc,
20
18
  vueContentCache,
21
19
  moduleId,
22
20
  callback
@@ -29,6 +27,7 @@ module.exports = function ({
29
27
  const defs = mpx.defs
30
28
  const resolveMode = mpx.resolveMode
31
29
  const pagesMap = mpx.pagesMap
30
+ const projectRoot = mpx.projectRoot
32
31
 
33
32
  let output = ''
34
33
  let usingComponents = [].concat(Object.keys(mpx.usingComponents))
@@ -66,7 +65,6 @@ module.exports = function ({
66
65
  resolveMode,
67
66
  loaderContext,
68
67
  pagesMap,
69
- pagesEntryMap: mpx.pagesEntryMap,
70
68
  pathHash: mpx.pathHash,
71
69
  componentsMap,
72
70
  projectRoot
@@ -89,7 +87,6 @@ module.exports = function ({
89
87
  srcMode,
90
88
  loaderContext,
91
89
  isProduction,
92
- getRequireForSrc,
93
90
  projectRoot,
94
91
  jsonConfig: jsonRes.jsonObj,
95
92
  componentId: queryObj.componentId || '',
@@ -3,10 +3,10 @@ const path = require('path')
3
3
  const JSON5 = require('json5')
4
4
  const loaderUtils = require('loader-utils')
5
5
  const parseRequest = require('../utils/parse-request')
6
- const toPosix = require('../utils/to-posix')
6
+ // const toPosix = require('../utils/to-posix')
7
7
  const addQuery = require('../utils/add-query')
8
8
  const parseComponent = require('../parser')
9
- const readJsonForSrc = require('../utils/read-json-for-src')
9
+ const getJSONContent = require('../utils/get-json-content')
10
10
  const isUrlRequest = require('../utils/is-url-request')
11
11
 
12
12
  module.exports = function (json, options, rawCallback) {
@@ -15,9 +15,8 @@ module.exports = function (json, options, rawCallback) {
15
15
  const defs = options.defs
16
16
  const loaderContext = options.loaderContext
17
17
  const resolveMode = options.resolveMode
18
- const pagesMap = options.pagesMap
18
+ // const pagesMap = options.pagesMap
19
19
  const componentsMap = options.componentsMap
20
- const pagesEntryMap = options.pagesEntryMap
21
20
  const projectRoot = options.projectRoot
22
21
  const pathHash = options.pathHash
23
22
  const localPagesMap = {}
@@ -30,17 +29,17 @@ module.exports = function (json, options, rawCallback) {
30
29
  let tabBarStr
31
30
  const context = loaderContext.context
32
31
 
33
- const emitWarning = (msg) => {
34
- loaderContext.emitWarning(
35
- new Error('[json processor][' + loaderContext.resource + ']: ' + msg)
36
- )
37
- }
32
+ // const emitWarning = (msg) => {
33
+ // loaderContext.emitWarning(
34
+ // new Error('[json processor][' + loaderContext.resource + ']: ' + msg)
35
+ // )
36
+ // }
38
37
 
39
- const emitError = (msg) => {
40
- this.emitError(
41
- new Error('[json compiler][' + this.resource + ']: ' + msg)
42
- )
43
- }
38
+ // const emitError = (msg) => {
39
+ // this.emitError(
40
+ // new Error('[json compiler][' + this.resource + ']: ' + msg)
41
+ // )
42
+ // }
44
43
 
45
44
  // const stringifyRequest = r => loaderUtils.stringifyRequest(loaderContext, r)
46
45
 
@@ -134,8 +133,8 @@ module.exports = function (json, options, rawCallback) {
134
133
  if (json.content) {
135
134
  content = json.content
136
135
  } else if (json.src) {
137
- return readJsonForSrc(json.src, loaderContext, (content) => {
138
- callback(null, result, content)
136
+ return getJSONContent(json || {}, loaderContext, (err, content) => {
137
+ callback(err, result, content)
139
138
  })
140
139
  }
141
140
  }
@@ -187,73 +186,69 @@ module.exports = function (json, options, rawCallback) {
187
186
  }
188
187
  }
189
188
 
190
- const getPageName = (resourcePath, ext) => {
191
- const baseName = path.basename(resourcePath, ext)
192
- return path.join('pages', baseName + pathHash(resourcePath), baseName)
193
- }
189
+ // const getPageName = (resourcePath, ext) => {
190
+ // const baseName = path.basename(resourcePath, ext)
191
+ // return path.join('pages', baseName + pathHash(resourcePath), baseName)
192
+ // }
194
193
 
195
194
  const processPages = (pages, srcRoot = '', tarRoot = '', context, callback) => {
196
195
  if (pages) {
197
196
  context = path.join(context, srcRoot)
198
197
  async.forEach(pages, (page, callback) => {
199
- let aliasPath = ''
198
+ let pagePath = page
200
199
  if (typeof page !== 'string') {
201
- aliasPath = page.path
202
- page = page.src
200
+ pagePath = page.src
203
201
  }
204
- if (!isUrlRequest(page, projectRoot)) return callback()
205
- if (resolveMode === 'native') {
206
- page = loaderUtils.urlToRequest(page, projectRoot)
207
- }
208
- resolve(context, page, (err, resource) => {
209
- if (err) return callback(err)
210
- const { resourcePath, queryObj } = parseRequest(resource)
211
- const ext = path.extname(resourcePath)
212
- // 获取pageName
213
- let pageName
214
- if (aliasPath) {
215
- pageName = toPosix(path.join(tarRoot, aliasPath))
216
- // 判断 key 存在重复情况直接报错
217
- for (let key in pagesMap) {
218
- if (pagesMap[key] === pageName && key !== resourcePath) {
219
- emitError(`Current page [${resourcePath}] registers a conflict page path [${pageName}] with existed page [${key}], which is not allowed, please rename it!`)
220
- return callback()
221
- }
222
- }
223
- } else {
224
- const relative = path.relative(context, resourcePath)
225
- if (/^\./.test(relative)) {
226
- // 如果当前page不存在于context中,对其进行重命名
227
- pageName = toPosix(path.join(tarRoot, getPageName(resourcePath, ext)))
228
- 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!`)
229
- } else {
230
- pageName = toPosix(path.join(tarRoot, /^(.*?)(\.[^.]*)?$/.exec(relative)[1]))
231
- // 如果当前page与已有page存在命名冲突,也进行重命名
232
- for (let key in pagesMap) {
233
- // 此处引入pagesEntryMap确保相同entry下路由路径重复注册才报错,不同entry下的路由路径重复则无影响
234
- if (pagesMap[key] === pageName && key !== resourcePath && pagesEntryMap[key] === loaderContext.resourcePath) {
235
- const pageNameRaw = pageName
236
- pageName = toPosix(path.join(tarRoot, getPageName(resourcePath, ext)))
237
- 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!`)
238
- break
239
- }
240
- }
241
- }
242
- }
243
- if (pagesMap[resourcePath]) {
244
- 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!`)
245
- return callback()
246
- }
247
- buildInfo.pagesMap = buildInfo.pagesMap || {}
248
- buildInfo.pagesMap[resourcePath] = pagesMap[resourcePath] = pageName
249
- pagesEntryMap[resourcePath] = loaderContext.resourcePath
250
- localPagesMap[pageName] = {
251
- resource: addQuery(resource, { page: true }),
252
- async: tarRoot || queryObj.async,
253
- isFirst: queryObj.isFirst
254
- }
255
- callback()
256
- })
202
+ // if (!isUrlRequest(page, projectRoot)) return callback()
203
+ // if (resolveMode === 'native') {
204
+ // page = loaderUtils.urlToRequest(page, projectRoot)
205
+ // }
206
+ // resolve(context, page, (err, resource) => {
207
+ // if (err) return callback(err)
208
+ // const { resourcePath, queryObj } = parseRequest(resource)
209
+ // const ext = path.extname(resourcePath)
210
+ // // 获取pageName
211
+ // let pageName
212
+ // if (aliasPath) {
213
+ // pageName = toPosix(path.join(tarRoot, aliasPath))
214
+ // // 判断 key 存在重复情况直接报错
215
+ // for (let key in pagesMap) {
216
+ // if (pagesMap[key] === pageName && key !== resourcePath) {
217
+ // emitError(`Current page [${resourcePath}] registers a conflict page path [${pageName}] with existed page [${key}], which is not allowed, please rename it!`)
218
+ // return callback()
219
+ // }
220
+ // }
221
+ // } else {
222
+ // const relative = path.relative(context, resourcePath)
223
+ // if (/^\./.test(relative)) {
224
+ // // 如果当前page不存在于context中,对其进行重命名
225
+ // pageName = toPosix(path.join(tarRoot, getPageName(resourcePath, ext)))
226
+ // 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!`)
227
+ // } else {
228
+ // pageName = toPosix(path.join(tarRoot, /^(.*?)(\.[^.]*)?$/.exec(relative)[1]))
229
+ // // 如果当前page与已有page存在命名冲突,也进行重命名
230
+ // for (let key in pagesMap) {
231
+ // // 此处引入pagesMap确保相同entry下路由路径重复注册才报错,不同entry下的路由路径重复则无影响
232
+ // if (pagesMap[key] === pageName && key !== resourcePath && pagesMap[key] === loaderContext.resourcePath) {
233
+ // const pageNameRaw = pageName
234
+ // pageName = toPosix(path.join(tarRoot, getPageName(resourcePath, ext)))
235
+ // 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!`)
236
+ // break
237
+ // }
238
+ // }
239
+ // }
240
+ // }
241
+ // if (pagesMap[resourcePath]) {
242
+ // 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!`)
243
+ // return callback()
244
+ // }
245
+ // buildInfo.pagesMap = buildInfo.pagesMap || {}
246
+ // buildInfo.pagesMap[resourcePath] = pagesMap[resourcePath] = pageName
247
+ // pagesMap[resourcePath] = loaderContext.resourcePath
248
+ localPagesMap[pagePath] = page
249
+ // callback()
250
+ // })
251
+ callback()
257
252
  }, callback)
258
253
  } else {
259
254
  callback()