@mpxjs/webpack-plugin 2.6.114-alpha.8 → 2.6.115
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/README.md +1 -1
- package/lib/built-in-loader.js +49 -0
- package/lib/config.js +0 -14
- package/lib/content-loader.js +13 -0
- package/lib/dependency/ChildCompileDependency.js +24 -0
- package/lib/dependency/InjectDependency.js +26 -0
- package/lib/dependency/RemovedModuleDependency.js +23 -0
- package/lib/{dependencies → dependency}/ReplaceDependency.js +2 -19
- package/lib/dependency/ResolveDependency.js +49 -0
- package/lib/extractor.js +178 -82
- package/lib/file-loader.js +19 -7
- package/lib/helpers.js +334 -39
- package/lib/index.js +525 -889
- package/lib/json-compiler/index.js +451 -245
- package/lib/json-compiler/{theme.js → theme-loader.js} +3 -5
- package/lib/loader.js +241 -178
- package/lib/native-loader.js +133 -71
- package/lib/parser.js +2 -1
- package/lib/path-loader.js +3 -0
- package/lib/platform/json/wx/index.js +1 -1
- package/lib/platform/template/normalize-component-rules.js +3 -2
- package/lib/platform/template/wx/component-config/button.js +2 -14
- package/lib/platform/template/wx/component-config/image.js +0 -4
- package/lib/platform/template/wx/component-config/input.js +0 -4
- package/lib/platform/template/wx/component-config/rich-text.js +0 -4
- package/lib/platform/template/wx/component-config/scroll-view.js +0 -4
- package/lib/platform/template/wx/component-config/switch.js +0 -4
- package/lib/platform/template/wx/component-config/text.js +0 -4
- package/lib/platform/template/wx/component-config/textarea.js +0 -5
- package/lib/platform/template/wx/component-config/view.js +0 -4
- package/lib/platform/template/wx/index.js +3 -149
- package/lib/plugin-loader.js +287 -0
- package/lib/resolver/AddEnvPlugin.js +3 -4
- package/lib/resolver/AddModePlugin.js +3 -4
- package/lib/resolver/PackageEntryPlugin.js +36 -23
- package/lib/runtime/base.styl +0 -5
- package/lib/runtime/components/web/getInnerListeners.js +3 -1
- package/lib/runtime/components/web/mpx-image.vue +5 -20
- package/lib/runtime/components/web/mpx-movable-view.vue +2 -6
- package/lib/runtime/components/web/mpx-swiper.vue +3 -18
- package/lib/runtime/i18n.wxs +11 -31
- package/lib/runtime/optionProcessor.js +3 -48
- package/lib/selector.js +10 -29
- package/lib/staticConfig.js +4 -0
- package/lib/style-compiler/index.js +24 -16
- package/lib/style-compiler/load-postcss-config.js +1 -3
- package/lib/style-compiler/plugins/conditional-strip.js +65 -68
- package/lib/style-compiler/plugins/rpx.js +37 -43
- package/lib/style-compiler/plugins/scope-id.js +72 -79
- package/lib/style-compiler/plugins/trans-special.js +18 -25
- package/lib/style-compiler/plugins/trim.js +7 -13
- package/lib/style-compiler/plugins/vw.js +16 -22
- package/lib/template-compiler/compiler.js +199 -106
- package/lib/template-compiler/index.js +139 -52
- package/lib/template-compiler/trans-dynamic-class-expr.js +13 -18
- package/lib/url-loader.js +29 -11
- package/lib/utils/add-query.js +1 -1
- package/lib/utils/get-main-compilation.js +6 -0
- package/lib/utils/is-url-request.js +1 -10
- package/lib/utils/match-condition.js +1 -4
- package/lib/utils/normalize.js +15 -4
- package/lib/utils/parse-request.js +3 -3
- package/lib/utils/read-json-for-src.js +34 -0
- package/lib/utils/stringify-query.js +0 -4
- package/lib/utils/try-require.js +16 -0
- package/lib/web/processJSON.js +144 -113
- package/lib/web/processScript.js +34 -47
- package/lib/web/processTemplate.js +40 -57
- package/lib/wxml/{loader.js → wxml-loader.js} +62 -21
- package/lib/wxs/WxsParserPlugin.js +2 -2
- package/lib/wxs/WxsPlugin.js +8 -4
- package/lib/wxs/WxsTemplatePlugin.js +92 -46
- package/lib/wxs/{i18n-loader.js → wxs-i18n-loader.js} +4 -5
- package/lib/wxs/wxs-loader.js +117 -0
- package/lib/wxs/{pre-loader.js → wxs-pre-loader.js} +5 -20
- package/lib/wxss/getImportPrefix.js +30 -0
- package/lib/wxss/loader.js +43 -31
- package/lib/wxss/localsLoader.js +5 -1
- package/lib/wxss/processCss.js +103 -107
- package/package.json +18 -21
- package/LICENSE +0 -433
- package/lib/dependencies/AddEntryDependency.js +0 -24
- package/lib/dependencies/AppEntryDependency.js +0 -58
- package/lib/dependencies/CommonJsAsyncDependency.js +0 -51
- package/lib/dependencies/CommonJsVariableDependency.js +0 -81
- package/lib/dependencies/DynamicEntryDependency.js +0 -171
- package/lib/dependencies/FlagPluginDependency.js +0 -24
- package/lib/dependencies/InjectDependency.js +0 -43
- package/lib/dependencies/RecordGlobalComponentsDependency.js +0 -50
- package/lib/dependencies/RecordIndependentDependency.js +0 -44
- package/lib/dependencies/RecordResourceMapDependency.js +0 -62
- package/lib/dependencies/RemoveEntryDependency.js +0 -40
- package/lib/dependencies/ResolveDependency.js +0 -88
- package/lib/independent-loader.js +0 -52
- package/lib/json-compiler/helper.js +0 -156
- package/lib/json-compiler/plugin.js +0 -150
- package/lib/partial-compile/index.js +0 -35
- package/lib/record-loader.js +0 -11
- package/lib/resolve-loader.js +0 -6
- package/lib/resolver/FixDescriptionInfoPlugin.js +0 -28
- package/lib/runtime/components/tenon/getInnerListeners.js +0 -317
- package/lib/runtime/components/tenon/tenon-button.vue +0 -305
- package/lib/runtime/components/tenon/tenon-image.vue +0 -61
- package/lib/runtime/components/tenon/tenon-input.vue +0 -99
- package/lib/runtime/components/tenon/tenon-rich-text.vue +0 -21
- package/lib/runtime/components/tenon/tenon-scroll-view.vue +0 -124
- package/lib/runtime/components/tenon/tenon-switch.vue +0 -91
- package/lib/runtime/components/tenon/tenon-text-area.vue +0 -64
- package/lib/runtime/components/tenon/tenon-text.vue +0 -64
- package/lib/runtime/components/tenon/tenon-view.vue +0 -93
- package/lib/runtime/components/tenon/util.js +0 -44
- package/lib/runtime/optionProcessor.tenon.js +0 -386
- package/lib/style-compiler/plugins/hm.js +0 -20
- package/lib/tenon/index.js +0 -105
- package/lib/tenon/processJSON.js +0 -360
- package/lib/tenon/processScript.js +0 -260
- package/lib/tenon/processStyles.js +0 -21
- package/lib/tenon/processTemplate.js +0 -133
- package/lib/utils/const.js +0 -10
- package/lib/utils/emit-file.js +0 -10
- package/lib/utils/eval-json-js.js +0 -31
- package/lib/utils/get-entry-name.js +0 -13
- package/lib/utils/get-json-content.js +0 -42
- package/lib/utils/get-relative-path.js +0 -24
- package/lib/utils/resolve.js +0 -13
- package/lib/utils/set.js +0 -47
- package/lib/utils/stringify-loaders-resource.js +0 -25
- package/lib/wxs/WxsModuleIdsPlugin.js +0 -29
- package/lib/wxs/loader.js +0 -142
package/lib/web/processJSON.js
CHANGED
|
@@ -6,30 +6,28 @@ 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
|
|
10
|
-
const
|
|
11
|
-
const createJSONHelper = require('../json-compiler/helper')
|
|
12
|
-
const { RESOLVE_IGNORED_ERR } = require('../utils/const')
|
|
13
|
-
const RecordResourceMapDependency = require('../dependencies/RecordResourceMapDependency')
|
|
9
|
+
const readJsonForSrc = require('../utils/read-json-for-src')
|
|
10
|
+
const isUrlRequest = require('../utils/is-url-request')
|
|
14
11
|
|
|
15
|
-
module.exports = function (json, {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
module.exports = function (json, 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 pagesEntryMap = options.pagesEntryMap
|
|
21
|
+
const projectRoot = options.projectRoot
|
|
22
|
+
const pathHash = options.pathHash
|
|
20
23
|
const localPagesMap = {}
|
|
21
24
|
const localComponentsMap = {}
|
|
25
|
+
const buildInfo = loaderContext._module.buildInfo
|
|
26
|
+
|
|
22
27
|
let output = '/* json */\n'
|
|
23
28
|
let jsonObj = {}
|
|
24
29
|
let tabBarMap
|
|
25
30
|
let tabBarStr
|
|
26
|
-
const mpx = loaderContext.getMpx()
|
|
27
|
-
const {
|
|
28
|
-
mode,
|
|
29
|
-
env,
|
|
30
|
-
projectRoot
|
|
31
|
-
} = mpx
|
|
32
|
-
|
|
33
31
|
const context = loaderContext.context
|
|
34
32
|
|
|
35
33
|
const emitWarning = (msg) => {
|
|
@@ -39,31 +37,13 @@ module.exports = function (json, {
|
|
|
39
37
|
}
|
|
40
38
|
|
|
41
39
|
const emitError = (msg) => {
|
|
42
|
-
|
|
43
|
-
new Error('[json compiler][' +
|
|
40
|
+
this.emitError(
|
|
41
|
+
new Error('[json compiler][' + this.resource + ']: ' + msg)
|
|
44
42
|
)
|
|
45
43
|
}
|
|
46
44
|
|
|
47
45
|
const stringifyRequest = r => loaderUtils.stringifyRequest(loaderContext, r)
|
|
48
46
|
|
|
49
|
-
const {
|
|
50
|
-
isUrlRequest,
|
|
51
|
-
urlToRequest,
|
|
52
|
-
processPage,
|
|
53
|
-
processComponent
|
|
54
|
-
} = createJSONHelper({
|
|
55
|
-
loaderContext,
|
|
56
|
-
emitWarning,
|
|
57
|
-
emitError,
|
|
58
|
-
customGetDynamicEntry (resource, type, outputPath, packageRoot) {
|
|
59
|
-
return {
|
|
60
|
-
resource,
|
|
61
|
-
outputPath: toPosix(path.join(packageRoot, outputPath)),
|
|
62
|
-
packageRoot
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
})
|
|
66
|
-
|
|
67
47
|
const callback = (err) => {
|
|
68
48
|
return rawCallback(err, {
|
|
69
49
|
output,
|
|
@@ -87,6 +67,12 @@ module.exports = function (json, {
|
|
|
87
67
|
|
|
88
68
|
const fs = loaderContext._compiler.inputFileSystem
|
|
89
69
|
|
|
70
|
+
const resolve = (context, request, callback) => {
|
|
71
|
+
const { queryObj } = parseRequest(request)
|
|
72
|
+
context = queryObj.context || context
|
|
73
|
+
return loaderContext.resolve(context, request, callback)
|
|
74
|
+
}
|
|
75
|
+
|
|
90
76
|
const defaultTabbar = {
|
|
91
77
|
borderStyle: 'black',
|
|
92
78
|
position: 'bottom',
|
|
@@ -104,7 +90,7 @@ module.exports = function (json, {
|
|
|
104
90
|
tabBarStr = JSON.stringify(tabBar)
|
|
105
91
|
tabBarStr = tabBarStr.replace(/"(iconPath|selectedIconPath)":"([^"]+)"/g, function (matched, $1, $2) {
|
|
106
92
|
if (isUrlRequest($2, projectRoot)) {
|
|
107
|
-
return `"${$1}":require(${stringifyRequest(urlToRequest($2, projectRoot))})`
|
|
93
|
+
return `"${$1}":require(${stringifyRequest(loaderUtils.urlToRequest($2, projectRoot))})`
|
|
108
94
|
}
|
|
109
95
|
return matched
|
|
110
96
|
})
|
|
@@ -114,37 +100,45 @@ module.exports = function (json, {
|
|
|
114
100
|
|
|
115
101
|
const processPackages = (packages, context, callback) => {
|
|
116
102
|
if (packages) {
|
|
117
|
-
async.
|
|
118
|
-
const
|
|
103
|
+
async.forEach(packages, (packagePath, callback) => {
|
|
104
|
+
const parsed = parseRequest(packagePath)
|
|
105
|
+
const queryObj = parsed.queryObj
|
|
106
|
+
// readFile无法处理query
|
|
107
|
+
packagePath = parsed.resourcePath
|
|
119
108
|
async.waterfall([
|
|
120
109
|
(callback) => {
|
|
121
|
-
resolve(context, packagePath,
|
|
122
|
-
|
|
123
|
-
const { rawResourcePath } = parseRequest(result)
|
|
124
|
-
callback(err, rawResourcePath)
|
|
110
|
+
resolve(context, packagePath, (err, result) => {
|
|
111
|
+
callback(err, result)
|
|
125
112
|
})
|
|
126
113
|
},
|
|
127
114
|
(result, callback) => {
|
|
115
|
+
loaderContext.addDependency(result)
|
|
128
116
|
fs.readFile(result, (err, content) => {
|
|
129
117
|
if (err) return callback(err)
|
|
130
118
|
callback(err, result, content.toString('utf-8'))
|
|
131
119
|
})
|
|
132
120
|
},
|
|
133
121
|
(result, content, callback) => {
|
|
134
|
-
const
|
|
135
|
-
|
|
122
|
+
const filePath = result
|
|
123
|
+
const extName = path.extname(filePath)
|
|
124
|
+
if (extName === '.mpx' || extName === '.vue') {
|
|
136
125
|
const parts = parseComponent(content, {
|
|
137
|
-
filePath
|
|
126
|
+
filePath,
|
|
138
127
|
needMap: loaderContext.sourceMap,
|
|
139
128
|
mode,
|
|
129
|
+
defs,
|
|
140
130
|
env
|
|
141
131
|
})
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
132
|
+
const json = parts.json || {}
|
|
133
|
+
if (json.content) {
|
|
134
|
+
content = json.content
|
|
135
|
+
} else if (json.src) {
|
|
136
|
+
return readJsonForSrc(json.src, loaderContext, (content) => {
|
|
137
|
+
callback(null, result, content)
|
|
138
|
+
})
|
|
139
|
+
}
|
|
147
140
|
}
|
|
141
|
+
callback(null, result, content)
|
|
148
142
|
},
|
|
149
143
|
(result, content, callback) => {
|
|
150
144
|
try {
|
|
@@ -165,17 +159,12 @@ module.exports = function (json, {
|
|
|
165
159
|
pages: content.pages,
|
|
166
160
|
...queryObj
|
|
167
161
|
}
|
|
168
|
-
|
|
169
|
-
if (content.plugins) {
|
|
170
|
-
subPackage.plugins = content.plugins
|
|
171
|
-
}
|
|
172
|
-
|
|
173
162
|
processSelfQueue.push((callback) => {
|
|
174
163
|
processSubPackage(subPackage, context, callback)
|
|
175
164
|
})
|
|
176
165
|
} else {
|
|
177
166
|
processSelfQueue.push((callback) => {
|
|
178
|
-
processPages(content.pages,
|
|
167
|
+
processPages(content.pages, '', '', context, callback)
|
|
179
168
|
})
|
|
180
169
|
}
|
|
181
170
|
}
|
|
@@ -190,40 +179,77 @@ module.exports = function (json, {
|
|
|
190
179
|
callback()
|
|
191
180
|
}
|
|
192
181
|
}
|
|
193
|
-
],
|
|
194
|
-
callback(err === RESOLVE_IGNORED_ERR ? null : err)
|
|
195
|
-
})
|
|
182
|
+
], callback)
|
|
196
183
|
}, callback)
|
|
197
184
|
} else {
|
|
198
185
|
callback()
|
|
199
186
|
}
|
|
200
187
|
}
|
|
201
188
|
|
|
202
|
-
const
|
|
189
|
+
const getPageName = (resourcePath, ext) => {
|
|
190
|
+
const baseName = path.basename(resourcePath, ext)
|
|
191
|
+
return path.join('pages', baseName + pathHash(resourcePath), baseName)
|
|
192
|
+
}
|
|
203
193
|
|
|
204
|
-
const processPages = (pages,
|
|
194
|
+
const processPages = (pages, srcRoot = '', tarRoot = '', context, callback) => {
|
|
205
195
|
if (pages) {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
196
|
+
context = path.join(context, srcRoot)
|
|
197
|
+
async.forEach(pages, (page, callback) => {
|
|
198
|
+
let aliasPath = ''
|
|
199
|
+
if (typeof page !== 'string') {
|
|
200
|
+
aliasPath = page.path
|
|
201
|
+
page = page.src
|
|
202
|
+
}
|
|
203
|
+
if (!isUrlRequest(page, projectRoot)) return callback()
|
|
204
|
+
if (resolveMode === 'native') {
|
|
205
|
+
page = loaderUtils.urlToRequest(page, projectRoot)
|
|
206
|
+
}
|
|
207
|
+
resolve(context, page, (err, resource) => {
|
|
208
|
+
if (err) return callback(err)
|
|
211
209
|
const { resourcePath, queryObj } = parseRequest(resource)
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
210
|
+
const ext = path.extname(resourcePath)
|
|
211
|
+
// 获取pageName
|
|
212
|
+
let pageName
|
|
213
|
+
if (aliasPath) {
|
|
214
|
+
pageName = toPosix(path.join(tarRoot, aliasPath))
|
|
215
|
+
// 判断 key 存在重复情况直接报错
|
|
216
|
+
for (let key in pagesMap) {
|
|
217
|
+
if (pagesMap[key] === pageName && key !== resourcePath) {
|
|
218
|
+
emitError(`Current page [${resourcePath}] registers a conflict page path [${pageName}] with existed page [${key}], which is not allowed, please rename it!`)
|
|
219
|
+
return callback()
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
} else {
|
|
223
|
+
const relative = path.relative(context, resourcePath)
|
|
224
|
+
if (/^\./.test(relative)) {
|
|
225
|
+
// 如果当前page不存在于context中,对其进行重命名
|
|
226
|
+
pageName = toPosix(path.join(tarRoot, getPageName(resourcePath, ext)))
|
|
227
|
+
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!`)
|
|
228
|
+
} else {
|
|
229
|
+
pageName = toPosix(path.join(tarRoot, /^(.*?)(\.[^.]*)?$/.exec(relative)[1]))
|
|
230
|
+
// 如果当前page与已有page存在命名冲突,也进行重命名
|
|
231
|
+
for (let key in pagesMap) {
|
|
232
|
+
// 此处引入pagesEntryMap确保相同entry下路由路径重复注册才报错,不同entry下的路由路径重复则无影响
|
|
233
|
+
if (pagesMap[key] === pageName && key !== resourcePath && pagesEntryMap[key] === loaderContext.resourcePath) {
|
|
234
|
+
const pageNameRaw = pageName
|
|
235
|
+
pageName = toPosix(path.join(tarRoot, getPageName(resourcePath, ext)))
|
|
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!`)
|
|
237
|
+
break
|
|
238
|
+
}
|
|
239
|
+
}
|
|
218
240
|
}
|
|
219
241
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
242
|
+
if (pagesMap[resourcePath]) {
|
|
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!`)
|
|
244
|
+
return callback()
|
|
245
|
+
}
|
|
246
|
+
buildInfo.pagesMap = buildInfo.pagesMap || {}
|
|
247
|
+
buildInfo.pagesMap[resourcePath] = pagesMap[resourcePath] = pageName
|
|
248
|
+
pagesEntryMap[resourcePath] = loaderContext.resourcePath
|
|
249
|
+
localPagesMap[pageName] = {
|
|
250
|
+
resource: addQuery(resource, { page: true }),
|
|
251
|
+
async: tarRoot || queryObj.async,
|
|
252
|
+
isFirst: queryObj.isFirst
|
|
227
253
|
}
|
|
228
254
|
callback()
|
|
229
255
|
})
|
|
@@ -235,15 +261,10 @@ module.exports = function (json, {
|
|
|
235
261
|
|
|
236
262
|
const processSubPackage = (subPackage, context, callback) => {
|
|
237
263
|
if (subPackage) {
|
|
238
|
-
if (typeof subPackage.root === 'string' && subPackage.root.startsWith('.')) {
|
|
239
|
-
emitError(`Current subpackage root [${subPackage.root}] is not allow starts with '.'`)
|
|
240
|
-
return callback()
|
|
241
|
-
}
|
|
242
264
|
let tarRoot = subPackage.tarRoot || subPackage.root || ''
|
|
243
265
|
let srcRoot = subPackage.srcRoot || subPackage.root || ''
|
|
244
266
|
if (!tarRoot) return callback()
|
|
245
|
-
|
|
246
|
-
processPages(subPackage.pages, context, tarRoot, callback)
|
|
267
|
+
processPages(subPackage.pages, srcRoot, tarRoot, context, callback)
|
|
247
268
|
} else {
|
|
248
269
|
callback()
|
|
249
270
|
}
|
|
@@ -251,7 +272,7 @@ module.exports = function (json, {
|
|
|
251
272
|
|
|
252
273
|
const processSubPackages = (subPackages, context, callback) => {
|
|
253
274
|
if (subPackages) {
|
|
254
|
-
async.
|
|
275
|
+
async.forEach(subPackages, (subPackage, callback) => {
|
|
255
276
|
processSubPackage(subPackage, context, callback)
|
|
256
277
|
}, callback)
|
|
257
278
|
} else {
|
|
@@ -261,37 +282,48 @@ module.exports = function (json, {
|
|
|
261
282
|
|
|
262
283
|
const processComponents = (components, context, callback) => {
|
|
263
284
|
if (components) {
|
|
264
|
-
async.
|
|
265
|
-
processComponent(component,
|
|
266
|
-
if (err === RESOLVE_IGNORED_ERR) {
|
|
267
|
-
return callback()
|
|
268
|
-
}
|
|
269
|
-
const { resourcePath, queryObj } = parseRequest(resource)
|
|
270
|
-
componentsMap[resourcePath] = outputPath
|
|
271
|
-
loaderContext._module && loaderContext._module.addPresentationalDependency(new RecordResourceMapDependency(resourcePath, 'component', outputPath))
|
|
272
|
-
localComponentsMap[name] = {
|
|
273
|
-
resource: addQuery(resource, {
|
|
274
|
-
isComponent: true,
|
|
275
|
-
outputPath
|
|
276
|
-
}),
|
|
277
|
-
async: queryObj.async
|
|
278
|
-
}
|
|
279
|
-
callback()
|
|
280
|
-
})
|
|
285
|
+
async.forEachOf(components, (component, name, callback) => {
|
|
286
|
+
processComponent(component, name, context, callback)
|
|
281
287
|
}, callback)
|
|
282
288
|
} else {
|
|
283
289
|
callback()
|
|
284
290
|
}
|
|
285
291
|
}
|
|
286
292
|
|
|
293
|
+
const processComponent = (component, name, context, callback) => {
|
|
294
|
+
if (!isUrlRequest(component, projectRoot)) return callback()
|
|
295
|
+
|
|
296
|
+
if (resolveMode === 'native') {
|
|
297
|
+
component = loaderUtils.urlToRequest(component, projectRoot)
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
resolve(context, component, (err, resource) => {
|
|
301
|
+
if (err) return callback(err)
|
|
302
|
+
const { resourcePath, queryObj } = parseRequest(resource)
|
|
303
|
+
const parsed = path.parse(resourcePath)
|
|
304
|
+
const componentId = parsed.name + pathHash(resourcePath)
|
|
305
|
+
|
|
306
|
+
buildInfo.packageName = 'main'
|
|
307
|
+
buildInfo.componentsMap = buildInfo.componentsMap || {}
|
|
308
|
+
buildInfo.componentsMap[resourcePath] = componentsMap[resourcePath] = componentId
|
|
309
|
+
|
|
310
|
+
localComponentsMap[name] = {
|
|
311
|
+
resource: addQuery(resource, { component: true, componentId }),
|
|
312
|
+
async: queryObj.async
|
|
313
|
+
}
|
|
314
|
+
callback()
|
|
315
|
+
})
|
|
316
|
+
}
|
|
317
|
+
|
|
287
318
|
const processGenerics = (generics, context, callback) => {
|
|
288
319
|
if (generics) {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
320
|
+
async.forEachOf(generics, (generic, name, callback) => {
|
|
321
|
+
if (generic.default) {
|
|
322
|
+
processComponent(generic.default, `${name}default`, context, callback)
|
|
323
|
+
} else {
|
|
324
|
+
callback()
|
|
325
|
+
}
|
|
326
|
+
}, callback)
|
|
295
327
|
} else {
|
|
296
328
|
callback()
|
|
297
329
|
}
|
|
@@ -299,7 +331,6 @@ module.exports = function (json, {
|
|
|
299
331
|
|
|
300
332
|
async.parallel([
|
|
301
333
|
(callback) => {
|
|
302
|
-
// 添加首页标识
|
|
303
334
|
if (jsonObj.pages && jsonObj.pages[0]) {
|
|
304
335
|
if (typeof jsonObj.pages[0] !== 'string') {
|
|
305
336
|
jsonObj.pages[0].src = addQuery(jsonObj.pages[0].src, { isFirst: true })
|
|
@@ -307,7 +338,7 @@ module.exports = function (json, {
|
|
|
307
338
|
jsonObj.pages[0] = addQuery(jsonObj.pages[0], { isFirst: true })
|
|
308
339
|
}
|
|
309
340
|
}
|
|
310
|
-
processPages(jsonObj.pages,
|
|
341
|
+
processPages(jsonObj.pages, '', '', context, callback)
|
|
311
342
|
},
|
|
312
343
|
(callback) => {
|
|
313
344
|
processComponents(jsonObj.usingComponents, context, callback)
|
package/lib/web/processScript.js
CHANGED
|
@@ -2,6 +2,7 @@ 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 builtInLoaderPath = normalize.lib('built-in-loader')
|
|
5
6
|
const optionProcessorPath = normalize.lib('runtime/optionProcessor')
|
|
6
7
|
const tabBarContainerPath = normalize.lib('runtime/components/web/mpx-tab-bar-container.vue')
|
|
7
8
|
const tabBarPath = normalize.lib('runtime/components/web/mpx-tab-bar.vue')
|
|
@@ -20,36 +21,24 @@ function shallowStringify (obj) {
|
|
|
20
21
|
return `{${arr.join(',')}}`
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
function
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
componentGenerics,
|
|
36
|
-
jsonConfig,
|
|
37
|
-
outputPath,
|
|
38
|
-
tabBarMap,
|
|
39
|
-
tabBarStr,
|
|
40
|
-
builtInComponentsMap,
|
|
41
|
-
genericsInfo,
|
|
42
|
-
wxsModuleMap,
|
|
43
|
-
localComponentsMap,
|
|
44
|
-
localPagesMap
|
|
45
|
-
}, callback) {
|
|
46
|
-
const mpx = loaderContext.getMpx()
|
|
47
|
-
const {
|
|
48
|
-
i18n,
|
|
49
|
-
projectRoot
|
|
50
|
-
} = mpx
|
|
51
|
-
|
|
24
|
+
module.exports = function (script, options, callback) {
|
|
25
|
+
const ctorType = options.ctorType
|
|
26
|
+
const builtInComponentsMap = options.builtInComponentsMap
|
|
27
|
+
const localComponentsMap = options.localComponentsMap
|
|
28
|
+
const localPagesMap = options.localPagesMap
|
|
29
|
+
const srcMode = options.srcMode
|
|
30
|
+
const loaderContext = options.loaderContext
|
|
31
|
+
const isProduction = options.isProduction
|
|
32
|
+
const componentId = options.componentId
|
|
33
|
+
const getRequireForSrc = options.getRequireForSrc
|
|
34
|
+
const i18n = options.i18n
|
|
35
|
+
const jsonConfig = options.jsonConfig
|
|
52
36
|
const tabBar = jsonConfig.tabBar
|
|
37
|
+
const tabBarMap = options.tabBarMap
|
|
38
|
+
const tabBarStr = options.tabBarStr
|
|
39
|
+
const genericsInfo = options.genericsInfo
|
|
40
|
+
const componentGenerics = options.componentGenerics
|
|
41
|
+
const forceDisableBuiltInLoader = options.forceDisableBuiltInLoader
|
|
53
42
|
|
|
54
43
|
const emitWarning = (msg) => {
|
|
55
44
|
loaderContext.emitWarning(
|
|
@@ -61,7 +50,7 @@ module.exports = function (script, {
|
|
|
61
50
|
let tabBarPagesMap = {}
|
|
62
51
|
if (tabBar && tabBarMap) {
|
|
63
52
|
// 挂载tabBar组件
|
|
64
|
-
const tabBarRequest = stringifyRequest(addQuery(tabBar.custom ? './custom-tab-bar/index' : tabBarPath, {
|
|
53
|
+
const tabBarRequest = stringifyRequest(addQuery(tabBar.custom ? './custom-tab-bar/index' : tabBarPath, { component: true }))
|
|
65
54
|
tabBarPagesMap['mpx-tab-bar'] = `getComponent(require(${tabBarRequest}))`
|
|
66
55
|
// 挂载tabBar页面
|
|
67
56
|
Object.keys(tabBarMap).forEach((pagePath) => {
|
|
@@ -69,7 +58,7 @@ module.exports = function (script, {
|
|
|
69
58
|
if (pageCfg) {
|
|
70
59
|
const pageRequest = stringifyRequest(pageCfg.resource)
|
|
71
60
|
if (pageCfg.async) {
|
|
72
|
-
tabBarPagesMap[pagePath] = `()=>import(${
|
|
61
|
+
tabBarPagesMap[pagePath] = `()=>import(${pageRequest}).then(res => getComponent(res, { __mpxPageRoute: ${JSON.stringify(pagePath)} }))`
|
|
73
62
|
} else {
|
|
74
63
|
tabBarPagesMap[pagePath] = `getComponent(require(${pageRequest}), { __mpxPageRoute: ${JSON.stringify(pagePath)} })`
|
|
75
64
|
}
|
|
@@ -119,7 +108,6 @@ module.exports = function (script, {
|
|
|
119
108
|
content += ` import '@mpxjs/webpack-plugin/lib/runtime/base.styl'
|
|
120
109
|
import Vue from 'vue'
|
|
121
110
|
import VueRouter from 'vue-router'
|
|
122
|
-
import Mpx from '@mpxjs/core'
|
|
123
111
|
Vue.use(VueRouter)
|
|
124
112
|
global.getApp = function(){}
|
|
125
113
|
global.getCurrentPages = function(){
|
|
@@ -137,8 +125,8 @@ module.exports = function (script, {
|
|
|
137
125
|
global.__networkTimeout = ${JSON.stringify(jsonConfig.networkTimeout)}
|
|
138
126
|
global.__mpxGenericsMap = {}
|
|
139
127
|
global.__style = ${JSON.stringify(jsonConfig.style || 'v1')}
|
|
140
|
-
global.__mpxPageConfig = ${JSON.stringify(jsonConfig.window)}
|
|
141
|
-
|
|
128
|
+
global.__mpxPageConfig = ${JSON.stringify(jsonConfig.window)}\n`
|
|
129
|
+
|
|
142
130
|
if (i18n) {
|
|
143
131
|
const i18nObj = Object.assign({}, i18n)
|
|
144
132
|
content += ` import VueI18n from 'vue-i18n'
|
|
@@ -161,15 +149,16 @@ module.exports = function (script, {
|
|
|
161
149
|
i18n.mergeLocaleMessage(locale, newMessages[locale])
|
|
162
150
|
})
|
|
163
151
|
}
|
|
164
|
-
|
|
165
|
-
|
|
152
|
+
if(global.__mpx) {
|
|
153
|
+
global.__mpx.i18n = i18n
|
|
154
|
+
}\n`
|
|
166
155
|
}
|
|
167
156
|
}
|
|
168
157
|
// 注入wxs模块
|
|
169
158
|
content += ' const wxsModules = {}\n'
|
|
170
|
-
if (wxsModuleMap) {
|
|
171
|
-
Object.keys(wxsModuleMap).forEach((module) => {
|
|
172
|
-
const src = loaderUtils.urlToRequest(wxsModuleMap[module], projectRoot)
|
|
159
|
+
if (options.wxsModuleMap) {
|
|
160
|
+
Object.keys(options.wxsModuleMap).forEach((module) => {
|
|
161
|
+
const src = loaderUtils.urlToRequest(options.wxsModuleMap[module], options.projectRoot)
|
|
173
162
|
const expression = `require(${stringifyRequest(src)})`
|
|
174
163
|
content += ` wxsModules.${module} = ${expression}\n`
|
|
175
164
|
})
|
|
@@ -184,7 +173,7 @@ module.exports = function (script, {
|
|
|
184
173
|
pagesMap[pagePath] = `getComponent(require(${stringifyRequest(tabBarContainerPath)}), { __mpxBuiltIn: true })`
|
|
185
174
|
} else {
|
|
186
175
|
if (pageCfg.async) {
|
|
187
|
-
pagesMap[pagePath] = `()=>import(${
|
|
176
|
+
pagesMap[pagePath] = `()=>import(${pageRequest}).then(res => getComponent(res, { __mpxPageRoute: ${JSON.stringify(pagePath)} }))`
|
|
188
177
|
} else {
|
|
189
178
|
// 为了保持小程序中app->page->component的js执行顺序,所有的page和component都改为require引入
|
|
190
179
|
pagesMap[pagePath] = `getComponent(require(${pageRequest}), { __mpxPageRoute: ${JSON.stringify(pagePath)} })`
|
|
@@ -200,7 +189,7 @@ module.exports = function (script, {
|
|
|
200
189
|
const componentCfg = localComponentsMap[componentName]
|
|
201
190
|
const componentRequest = stringifyRequest(componentCfg.resource)
|
|
202
191
|
if (componentCfg.async) {
|
|
203
|
-
componentsMap[componentName] = `()=>import(${
|
|
192
|
+
componentsMap[componentName] = `()=>import(${componentRequest}).then(res => getComponent(res))`
|
|
204
193
|
} else {
|
|
205
194
|
componentsMap[componentName] = `getComponent(require(${componentRequest}))`
|
|
206
195
|
}
|
|
@@ -208,7 +197,7 @@ module.exports = function (script, {
|
|
|
208
197
|
|
|
209
198
|
Object.keys(builtInComponentsMap).forEach((componentName) => {
|
|
210
199
|
const componentCfg = builtInComponentsMap[componentName]
|
|
211
|
-
const componentRequest = stringifyRequest(componentCfg.resource)
|
|
200
|
+
const componentRequest = forceDisableBuiltInLoader ? stringifyRequest(componentCfg.resource) : stringifyRequest('builtInComponent.vue!=!' + builtInLoaderPath + '!' + componentCfg.resource)
|
|
212
201
|
componentsMap[componentName] = `getComponent(require(${componentRequest}), { __mpxBuiltIn: true })`
|
|
213
202
|
})
|
|
214
203
|
|
|
@@ -217,11 +206,9 @@ module.exports = function (script, {
|
|
|
217
206
|
content += ` global.currentResource = ${JSON.stringify(loaderContext.resourcePath)}\n`
|
|
218
207
|
}
|
|
219
208
|
// 为了正确获取currentSrcMode便于运行时进行转换,对于src引入的组件script采用require方式引入(由于webpack会将import的执行顺序上升至最顶),这意味着对于src引入脚本中的named export将不会生效,不过鉴于mpx和小程序中本身也没有在组件script中声明export的用法,所以应该没有影响
|
|
220
|
-
content += '\n\n\n/** Source start **/\n'
|
|
221
209
|
content += script.src
|
|
222
|
-
?
|
|
223
|
-
: script.content
|
|
224
|
-
content += '\n/** Source end **/\n\n\n'
|
|
210
|
+
? (getRequireForSrc('script', script) + '\n')
|
|
211
|
+
: (script.content + '\n') + '\n'
|
|
225
212
|
// createApp/Page/Component执行完成后立刻获取当前的option并暂存
|
|
226
213
|
content += ` const currentOption = global.currentOption\n`
|
|
227
214
|
// 获取pageConfig
|
|
@@ -252,7 +239,7 @@ module.exports = function (script, {
|
|
|
252
239
|
currentOption,
|
|
253
240
|
${JSON.stringify(ctorType)},
|
|
254
241
|
${JSON.stringify(firstPage)},
|
|
255
|
-
${JSON.stringify(
|
|
242
|
+
${JSON.stringify(componentId)},
|
|
256
243
|
${JSON.stringify(pageConfig)},
|
|
257
244
|
// @ts-ignore
|
|
258
245
|
${shallowStringify(pagesMap)},
|