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