@mpxjs/webpack-plugin 2.7.1-beta.3 → 2.7.1-beta.4
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/helpers.js +4 -3
- package/lib/independent-loader.js +2 -0
- package/lib/loader.js +22 -8
- package/lib/native-loader.js +3 -2
- package/package.json +2 -2
package/lib/helpers.js
CHANGED
|
@@ -14,6 +14,7 @@ const defaultLang = {
|
|
|
14
14
|
|
|
15
15
|
module.exports = function createHelpers (loaderContext) {
|
|
16
16
|
const rawRequest = loaderUtils.getRemainingRequest(loaderContext)
|
|
17
|
+
const { resourcePath, queryObj } = parseRequest(loaderContext.resource)
|
|
17
18
|
|
|
18
19
|
function getRequire (type, part, extraOptions, index) {
|
|
19
20
|
return 'require(' + getRequestString(type, part, extraOptions, index) + ')'
|
|
@@ -35,9 +36,9 @@ module.exports = function createHelpers (loaderContext) {
|
|
|
35
36
|
|
|
36
37
|
function getFakeRequest (type, part) {
|
|
37
38
|
const lang = part.lang || defaultLang[type] || type
|
|
38
|
-
const {
|
|
39
|
-
if (lang === 'json')
|
|
40
|
-
return addQuery(`${resourcePath}.${lang}`,
|
|
39
|
+
const options = { ...queryObj }
|
|
40
|
+
if (lang === 'json') options.asScript = true
|
|
41
|
+
return addQuery(`${resourcePath}.${lang}`, options)
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
function getRequestString (type, part, extraOptions = {}, index = 0) {
|
|
@@ -41,6 +41,8 @@ module.exports = function (content) {
|
|
|
41
41
|
const i18nWxsLoaderPath = normalize.lib('wxs/i18n-loader.js')
|
|
42
42
|
const i18nWxsRequest = i18nWxsLoaderPath + '!' + i18nWxsPath
|
|
43
43
|
this._module.addDependency(new CommonJsVariableDependency(i18nWxsRequest))
|
|
44
|
+
// 避免该模块被concatenate导致注入的i18n没有最先执行
|
|
45
|
+
this._module.buildInfo.moduleConcatenationBailout = 'i18n'
|
|
44
46
|
}
|
|
45
47
|
output += content
|
|
46
48
|
output += '\n'
|
package/lib/loader.js
CHANGED
|
@@ -225,6 +225,8 @@ module.exports = function (content) {
|
|
|
225
225
|
const i18nWxsLoaderPath = normalize.lib('wxs/i18n-loader.js')
|
|
226
226
|
const i18nWxsRequest = i18nWxsLoaderPath + '!' + i18nWxsPath
|
|
227
227
|
this._module.addDependency(new CommonJsVariableDependency(i18nWxsRequest))
|
|
228
|
+
// 避免该模块被concatenate导致注入的i18n没有最先执行
|
|
229
|
+
this._module.buildInfo.moduleConcatenationBailout = 'i18n'
|
|
228
230
|
}
|
|
229
231
|
|
|
230
232
|
// 为独立分包注入init module
|
|
@@ -232,6 +234,8 @@ module.exports = function (content) {
|
|
|
232
234
|
const independentLoader = normalize.lib('independent-loader.js')
|
|
233
235
|
const independentInitRequest = `!!${independentLoader}!${independent}`
|
|
234
236
|
this._module.addDependency(new CommonJsVariableDependency(independentInitRequest))
|
|
237
|
+
// 避免该模块被concatenate导致注入的independent init没有最先执行
|
|
238
|
+
this._module.buildInfo.moduleConcatenationBailout = 'independent init'
|
|
235
239
|
}
|
|
236
240
|
|
|
237
241
|
// 注入构造函数
|
|
@@ -258,6 +262,10 @@ module.exports = function (content) {
|
|
|
258
262
|
|
|
259
263
|
if (template) {
|
|
260
264
|
const extraOptions = {
|
|
265
|
+
...template.src ? {
|
|
266
|
+
...queryObj,
|
|
267
|
+
resourcePath
|
|
268
|
+
} : null,
|
|
261
269
|
hasScoped,
|
|
262
270
|
hasComment,
|
|
263
271
|
isNative,
|
|
@@ -278,16 +286,16 @@ module.exports = function (content) {
|
|
|
278
286
|
parts.styles.forEach((style, i) => {
|
|
279
287
|
const scoped = style.scoped || autoScope
|
|
280
288
|
const extraOptions = {
|
|
289
|
+
// style src会被特殊处理为全局复用样式,不添加resourcePath,添加isStatic及issuerFile
|
|
290
|
+
...style.src ? {
|
|
291
|
+
...queryObj,
|
|
292
|
+
isStatic: true,
|
|
293
|
+
issuerFile: mpx.getExtractedFile(addQuery(this.resource, { type: 'styles' }, true))
|
|
294
|
+
} : null,
|
|
281
295
|
moduleId,
|
|
282
296
|
scoped
|
|
283
297
|
}
|
|
284
298
|
// require style
|
|
285
|
-
if (style.src) {
|
|
286
|
-
// style src会被特殊处理为全局复用样式,不添加resourcePath,添加isStatic及issuerFile
|
|
287
|
-
extraOptions.isStatic = true
|
|
288
|
-
const issuerResource = addQuery(this.resource, { type: 'styles' }, true)
|
|
289
|
-
extraOptions.issuerFile = mpx.getExtractedFile(issuerResource)
|
|
290
|
-
}
|
|
291
299
|
output += getRequire('styles', style, extraOptions, i) + '\n'
|
|
292
300
|
})
|
|
293
301
|
} else if (ctorType === 'app' && mode === 'ali') {
|
|
@@ -298,7 +306,10 @@ module.exports = function (content) {
|
|
|
298
306
|
output += '/* json */\n'
|
|
299
307
|
// 给予json默认值, 确保生成json request以自动补全json
|
|
300
308
|
const json = parts.json || {}
|
|
301
|
-
output += getRequire('json', json, json.src && {
|
|
309
|
+
output += getRequire('json', json, json.src && {
|
|
310
|
+
...queryObj,
|
|
311
|
+
resourcePath
|
|
312
|
+
}) + '\n'
|
|
302
313
|
|
|
303
314
|
// script
|
|
304
315
|
output += '/* script */\n'
|
|
@@ -310,9 +321,12 @@ module.exports = function (content) {
|
|
|
310
321
|
if (scriptSrcMode) output += `global.currentSrcMode = ${JSON.stringify(scriptSrcMode)}\n`
|
|
311
322
|
// 传递ctorType以补全js内容
|
|
312
323
|
const extraOptions = {
|
|
324
|
+
...script.src ? {
|
|
325
|
+
...queryObj,
|
|
326
|
+
resourcePath
|
|
327
|
+
} : null,
|
|
313
328
|
ctorType
|
|
314
329
|
}
|
|
315
|
-
if (script.src) extraOptions.resourcePath = resourcePath
|
|
316
330
|
output += getRequire('script', script, extraOptions) + '\n'
|
|
317
331
|
}
|
|
318
332
|
callback(null, output)
|
package/lib/native-loader.js
CHANGED
|
@@ -137,9 +137,10 @@ module.exports = function (content) {
|
|
|
137
137
|
const getRequireByType = (type) => {
|
|
138
138
|
const src = typeResourceMap[type]
|
|
139
139
|
const part = { src }
|
|
140
|
-
const extraOptions =
|
|
140
|
+
const extraOptions = {
|
|
141
|
+
...queryObj,
|
|
141
142
|
resourcePath
|
|
142
|
-
}
|
|
143
|
+
}
|
|
143
144
|
|
|
144
145
|
switch (type) {
|
|
145
146
|
case 'template':
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.7.1-beta.
|
|
3
|
+
"version": "2.7.1-beta.4",
|
|
4
4
|
"description": "mpx compile core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mpx"
|
|
@@ -80,5 +80,5 @@
|
|
|
80
80
|
"engines": {
|
|
81
81
|
"node": ">=14.14.0"
|
|
82
82
|
},
|
|
83
|
-
"gitHead": "
|
|
83
|
+
"gitHead": "bb23a30c136854abc94e9b31a36b0857a00e45d4"
|
|
84
84
|
}
|