@mpxjs/webpack-plugin 2.6.114-alpha.7 → 2.6.114-alpha.8
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.
- package/lib/tenon/index.js +0 -1
- package/lib/tenon/processJSON.js +8 -9
- package/lib/tenon/processScript.js +20 -32
- package/package.json +2 -2
package/lib/tenon/index.js
CHANGED
package/lib/tenon/processJSON.js
CHANGED
|
@@ -6,7 +6,7 @@ const parseRequest = require('../utils/parse-request')
|
|
|
6
6
|
const toPosix = require('../utils/to-posix')
|
|
7
7
|
const addQuery = require('../utils/add-query')
|
|
8
8
|
const parseComponent = require('../parser')
|
|
9
|
-
const
|
|
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) {
|
|
@@ -17,7 +17,6 @@ module.exports = function (json, options, rawCallback) {
|
|
|
17
17
|
const resolveMode = options.resolveMode
|
|
18
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 = {}
|
|
@@ -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
|
|
138
|
-
callback(
|
|
136
|
+
return getJSONContent(json || {}, loaderContext, (err, content) => {
|
|
137
|
+
callback(err, result, content)
|
|
139
138
|
})
|
|
140
139
|
}
|
|
141
140
|
}
|
|
@@ -230,8 +229,8 @@ module.exports = function (json, options, rawCallback) {
|
|
|
230
229
|
pageName = toPosix(path.join(tarRoot, /^(.*?)(\.[^.]*)?$/.exec(relative)[1]))
|
|
231
230
|
// 如果当前page与已有page存在命名冲突,也进行重命名
|
|
232
231
|
for (let key in pagesMap) {
|
|
233
|
-
// 此处引入
|
|
234
|
-
if (pagesMap[key] === pageName && key !== resourcePath &&
|
|
232
|
+
// 此处引入pagesMap确保相同entry下路由路径重复注册才报错,不同entry下的路由路径重复则无影响
|
|
233
|
+
if (pagesMap[key] === pageName && key !== resourcePath && pagesMap[key] === loaderContext.resourcePath) {
|
|
235
234
|
const pageNameRaw = pageName
|
|
236
235
|
pageName = toPosix(path.join(tarRoot, getPageName(resourcePath, ext)))
|
|
237
236
|
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!`)
|
|
@@ -244,9 +243,9 @@ module.exports = function (json, options, rawCallback) {
|
|
|
244
243
|
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
244
|
return callback()
|
|
246
245
|
}
|
|
247
|
-
buildInfo.pagesMap = buildInfo.pagesMap || {}
|
|
248
|
-
buildInfo.pagesMap[resourcePath] = pagesMap[resourcePath] = pageName
|
|
249
|
-
|
|
246
|
+
// buildInfo.pagesMap = buildInfo.pagesMap || {}
|
|
247
|
+
// buildInfo.pagesMap[resourcePath] = pagesMap[resourcePath] = pageName
|
|
248
|
+
// pagesMap[resourcePath] = loaderContext.resourcePath
|
|
250
249
|
localPagesMap[pageName] = {
|
|
251
250
|
resource: addQuery(resource, { page: true }),
|
|
252
251
|
async: tarRoot || queryObj.async,
|
|
@@ -2,11 +2,10 @@ const genComponentTag = require('../utils/gen-component-tag')
|
|
|
2
2
|
const loaderUtils = require('loader-utils')
|
|
3
3
|
const addQuery = require('../utils/add-query')
|
|
4
4
|
const normalize = require('../utils/normalize')
|
|
5
|
-
// const SingleEntryPlugin = require('webpack/lib/SingleEntryPlugin')
|
|
6
|
-
// const AddEntryDependency = require('../dependency/AddEntryDependency')
|
|
7
5
|
const builtInLoaderPath = normalize.lib('built-in-loader')
|
|
8
6
|
const optionProcessorPath = normalize.lib('runtime/optionProcessor')
|
|
9
7
|
const createJSONHelper = require('../json-compiler/helper')
|
|
8
|
+
const async = require('async')
|
|
10
9
|
|
|
11
10
|
function shallowStringify (obj) {
|
|
12
11
|
let arr = []
|
|
@@ -22,11 +21,6 @@ function shallowStringify (obj) {
|
|
|
22
21
|
return `{${arr.join(',')}}`
|
|
23
22
|
}
|
|
24
23
|
|
|
25
|
-
// let entryDeps = new Set()
|
|
26
|
-
|
|
27
|
-
// let callbacked = false
|
|
28
|
-
// let cacheCallback
|
|
29
|
-
|
|
30
24
|
module.exports = function (script, options, callback) {
|
|
31
25
|
const ctorType = options.ctorType
|
|
32
26
|
const builtInComponentsMap = options.builtInComponentsMap
|
|
@@ -85,7 +79,8 @@ module.exports = function (script, options, callback) {
|
|
|
85
79
|
}
|
|
86
80
|
|
|
87
81
|
const {
|
|
88
|
-
|
|
82
|
+
processPage,
|
|
83
|
+
processDynamicEntry
|
|
89
84
|
} = createJSONHelper({
|
|
90
85
|
loaderContext,
|
|
91
86
|
emitWarning,
|
|
@@ -170,27 +165,6 @@ module.exports = function (script, options, callback) {
|
|
|
170
165
|
let firstPage = ''
|
|
171
166
|
const pagesMap = {}
|
|
172
167
|
const componentsMap = {}
|
|
173
|
-
Object.keys(localPagesMap).forEach((pagePath) => {
|
|
174
|
-
const pageCfg = localPagesMap[pagePath]
|
|
175
|
-
// const pageRequest = stringifyRequest(pageCfg.resource)
|
|
176
|
-
processJsExport(addQuery(pageCfg.resource, { tenon: true }), loaderContext.context, '', () => {})
|
|
177
|
-
// addEntryDep(loaderContext, addQuery(pageCfg.resource, { tenon: true }), pagePath)
|
|
178
|
-
// addEntrySafely(loaderContext, addQuery(pageCfg.resource, { tenon: true }), pagePath)
|
|
179
|
-
// loaderContext.resolve(loaderContext._compiler.context, addQuery(pageCfg.resource, { tenon: true }), (err, resource) => {
|
|
180
|
-
// if(err) return callback(err)
|
|
181
|
-
|
|
182
|
-
// })
|
|
183
|
-
// if (pageCfg.async) {
|
|
184
|
-
// pagesMap[pagePath] = `()=>import(${pageRequest}).then(res => getComponent(res, { __mpxPageRoute: ${JSON.stringify(pagePath)} }))`
|
|
185
|
-
// } else {
|
|
186
|
-
// // 为了保持小程序中app->page->component的js执行顺序,所有的page和component都改为require引入
|
|
187
|
-
// pagesMap[pagePath] = `getComponent(require(${pageRequest}), { __mpxPageRoute: ${JSON.stringify(pagePath)} })`
|
|
188
|
-
// }
|
|
189
|
-
|
|
190
|
-
// if (pageCfg.isFirst) {
|
|
191
|
-
// firstPage = pagePath
|
|
192
|
-
// }
|
|
193
|
-
})
|
|
194
168
|
|
|
195
169
|
Object.keys(localComponentsMap).forEach((componentName) => {
|
|
196
170
|
const componentCfg = localComponentsMap[componentName]
|
|
@@ -261,12 +235,26 @@ module.exports = function (script, options, callback) {
|
|
|
261
235
|
// i18n`
|
|
262
236
|
// }
|
|
263
237
|
// }
|
|
264
|
-
content += `\n )\n`
|
|
238
|
+
content += `\n )\n__dynamic_page_slot__\n`
|
|
265
239
|
return content
|
|
266
240
|
}
|
|
267
241
|
})
|
|
268
242
|
output += '\n'
|
|
269
|
-
|
|
270
|
-
|
|
243
|
+
// 处理pages
|
|
244
|
+
const pageSet = new Set()
|
|
245
|
+
let dynamicPageStr = ''
|
|
246
|
+
async.each(localPagesMap, (pageCfg, callback) => {
|
|
247
|
+
processPage(addQuery(pageCfg.resource, { tenon: true }), loaderContext.context, '', (err, entry, { key }) => {
|
|
248
|
+
if (err) return callback()
|
|
249
|
+
if (pageSet.has(key)) return callback()
|
|
250
|
+
pageSet.add(key)
|
|
251
|
+
dynamicPageStr += `\n"${entry}"`
|
|
252
|
+
callback()
|
|
253
|
+
})
|
|
254
|
+
}, () => {
|
|
255
|
+
output = output.replace('__dynamic_page_slot__', processDynamicEntry(dynamicPageStr) || '')
|
|
256
|
+
callback(null, {
|
|
257
|
+
output
|
|
258
|
+
})
|
|
271
259
|
})
|
|
272
260
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.6.114-alpha.
|
|
3
|
+
"version": "2.6.114-alpha.8",
|
|
4
4
|
"description": "mpx compile core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mpx"
|
|
@@ -83,5 +83,5 @@
|
|
|
83
83
|
"engines": {
|
|
84
84
|
"node": ">=14.14.0"
|
|
85
85
|
},
|
|
86
|
-
"gitHead": "
|
|
86
|
+
"gitHead": "f6a3d039dbe797630651f9d945b8755a5f05e528"
|
|
87
87
|
}
|