@mpxjs/webpack-plugin 2.7.5 → 2.7.6
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.
|
@@ -117,8 +117,11 @@ class DynamicEntryDependency extends NullDependency {
|
|
|
117
117
|
|
|
118
118
|
DynamicEntryDependency.Template = class DynamicEntryDependencyTemplate {
|
|
119
119
|
apply (dep, source) {
|
|
120
|
-
const { resultPath, range, key } = dep
|
|
121
|
-
if (
|
|
120
|
+
const { resultPath, range, key, outputPath } = dep
|
|
121
|
+
if (outputPath === 'custom-tab-bar/index') {
|
|
122
|
+
// replace with true for custom-tab-bar
|
|
123
|
+
source.replace(range[0], range[1] - 1, 'true')
|
|
124
|
+
} else if (resultPath) {
|
|
122
125
|
source.replace(range[0], range[1] - 1, JSON.stringify(resultPath))
|
|
123
126
|
} else {
|
|
124
127
|
const replaceRange = `mpx_replace_path_${key}`
|
package/lib/index.js
CHANGED
|
@@ -279,7 +279,7 @@ class MpxWebpackPlugin {
|
|
|
279
279
|
|
|
280
280
|
const addModePlugin = new AddModePlugin('before-file', this.options.mode, this.options.fileConditionRules, 'file')
|
|
281
281
|
const addEnvPlugin = new AddEnvPlugin('before-file', this.options.env, this.options.fileConditionRules, 'file')
|
|
282
|
-
const packageEntryPlugin = new PackageEntryPlugin('before-
|
|
282
|
+
const packageEntryPlugin = new PackageEntryPlugin('before-file', this.options.miniNpmPackages, 'file')
|
|
283
283
|
if (Array.isArray(compiler.options.resolve.plugins)) {
|
|
284
284
|
compiler.options.resolve.plugins.push(addModePlugin)
|
|
285
285
|
} else {
|
|
@@ -474,11 +474,12 @@ module.exports = function (content) {
|
|
|
474
474
|
|
|
475
475
|
const processCustomTabBar = (tabBar, context, callback) => {
|
|
476
476
|
if (tabBar && tabBar.custom) {
|
|
477
|
-
processComponent('./custom-tab-bar/index', context, { outputPath: 'custom-tab-bar/index' }, (err) => {
|
|
477
|
+
processComponent('./custom-tab-bar/index', context, { outputPath: 'custom-tab-bar/index' }, (err, entry) => {
|
|
478
478
|
if (err === RESOLVE_IGNORED_ERR) {
|
|
479
479
|
delete tabBar.custom
|
|
480
480
|
return callback()
|
|
481
481
|
}
|
|
482
|
+
tabBar.custom = entry // hack for javascript parser call hook.
|
|
482
483
|
callback(err)
|
|
483
484
|
})
|
|
484
485
|
} else {
|
|
@@ -1,55 +1,42 @@
|
|
|
1
1
|
const path = require('path')
|
|
2
|
-
|
|
3
|
-
* @desc 获取小程序npm包资源入口目录
|
|
4
|
-
*/
|
|
5
|
-
const getEntry = (name, miniprogram) => {
|
|
6
|
-
return path.join(name, miniprogram)
|
|
7
|
-
}
|
|
2
|
+
const toPosix = require('../utils/to-posix')
|
|
8
3
|
|
|
9
4
|
module.exports = class PackageEntryPlugin {
|
|
10
|
-
constructor (source,
|
|
5
|
+
constructor (source, miniNpmPackages, target) {
|
|
11
6
|
this.source = source
|
|
12
7
|
this.target = target
|
|
13
|
-
this.
|
|
8
|
+
this.miniNpmPackages = miniNpmPackages
|
|
14
9
|
}
|
|
15
10
|
|
|
16
11
|
/**
|
|
17
12
|
* 判断是否需要更改innerRequest
|
|
18
13
|
* 小程序发布npm包约束: package.json配置miniprogram 或默认 miniprogram_dist目录
|
|
19
|
-
* 0. 前提: request中含有package.json中name字段
|
|
20
14
|
* 1. package.json中配置了miniprogram, 且request中不含miniprogram,尝试拼接
|
|
21
|
-
* 2. 用户配置
|
|
15
|
+
* 2. 用户配置miniNpmPackages说明是小程序npm包,如果package.json中没配置miniprogram字段,则尝试拼接默认miniprogram_dist目录
|
|
22
16
|
*/
|
|
23
17
|
apply (resolver) {
|
|
24
18
|
const target = resolver.ensureHook(this.target)
|
|
25
19
|
resolver.getHook(this.source).tapAsync('PackagePlugin', (request, resolveContext, callback) => {
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
if (request.miniprogram) return callback()
|
|
21
|
+
let { path: resourcePath, descriptionFileData, descriptionFileRoot } = request
|
|
22
|
+
if (request.miniprogram || !descriptionFileData) return callback()
|
|
23
|
+
|
|
24
|
+
let { name, miniprogram } = descriptionFileData
|
|
25
|
+
if (!miniprogram && this.miniNpmPackages.includes(name)) miniprogram = 'miniprogram_dist'
|
|
26
|
+
if (!miniprogram) return callback()
|
|
27
|
+
|
|
28
|
+
let relativePath = path.relative(descriptionFileRoot, resourcePath)
|
|
29
|
+
if (relativePath.startsWith(miniprogram)) return callback()
|
|
30
|
+
|
|
31
|
+
relativePath = path.join(miniprogram, relativePath)
|
|
28
32
|
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (innerRequest.indexOf(normalizedName) === -1) {
|
|
35
|
-
return callback()
|
|
36
|
-
}
|
|
37
|
-
if (miniprogram) {
|
|
38
|
-
newEntry = getEntry(normalizedName, miniprogram)
|
|
39
|
-
} else if (this.miniNpmPackage.includes(name)) {
|
|
40
|
-
newEntry = getEntry(normalizedName, 'miniprogram_dist')
|
|
41
|
-
}
|
|
33
|
+
const obj = Object.assign({}, request, {
|
|
34
|
+
path: path.join(descriptionFileRoot, relativePath),
|
|
35
|
+
relativePath: './' + toPosix(relativePath),
|
|
36
|
+
miniprogram: true
|
|
37
|
+
})
|
|
42
38
|
|
|
43
|
-
|
|
44
|
-
const newRequest = innerRequest.replace(normalizedName, newEntry)
|
|
45
|
-
const obj = Object.assign({}, request, {
|
|
46
|
-
request: newRequest,
|
|
47
|
-
miniprogram: true
|
|
48
|
-
})
|
|
49
|
-
resolver.doResolve(target, obj, `change request ${innerRequest} to :` + newRequest, resolveContext, callback)
|
|
50
|
-
} else {
|
|
51
|
-
callback()
|
|
52
|
-
}
|
|
39
|
+
resolver.doResolve(target, obj, 'add miniprogram dist: ' + miniprogram, resolveContext, callback)
|
|
53
40
|
})
|
|
54
41
|
}
|
|
55
42
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.6",
|
|
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": "2005cbdd935b0f7a193d41e7bb3d12c4a5f62e96"
|
|
84
84
|
}
|