@mpxjs/webpack-plugin 2.7.43 → 2.7.46
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 +3 -1
- package/lib/index.js +21 -6
- package/lib/selector.js +5 -5
- package/lib/wxs/WxsPlugin.js +8 -0
- package/lib/wxs/WxsTemplatePlugin.js +71 -1
- package/package.json +2 -2
package/lib/helpers.js
CHANGED
|
@@ -16,6 +16,8 @@ module.exports = function createHelpers (loaderContext) {
|
|
|
16
16
|
const rawRequest = loaderUtils.getRemainingRequest(loaderContext)
|
|
17
17
|
const { resourcePath, queryObj } = parseRequest(loaderContext.resource)
|
|
18
18
|
|
|
19
|
+
const { mode, env } = loaderContext.getMpx() || {}
|
|
20
|
+
|
|
19
21
|
function getRequire (type, part, extraOptions, index) {
|
|
20
22
|
return 'require(' + getRequestString(type, part, extraOptions, index) + ')'
|
|
21
23
|
}
|
|
@@ -66,7 +68,7 @@ module.exports = function createHelpers (loaderContext) {
|
|
|
66
68
|
return loaderUtils.stringifyRequest(loaderContext, addQuery(src, options, true))
|
|
67
69
|
} else {
|
|
68
70
|
const fakeRequest = getFakeRequest(type, part)
|
|
69
|
-
const request = `${selectorPath}!${addQuery(rawRequest, options, true)}`
|
|
71
|
+
const request = `${selectorPath}?mode=${mode}&env=${env}!${addQuery(rawRequest, options, true)}`
|
|
70
72
|
return loaderUtils.stringifyRequest(loaderContext, `${fakeRequest}!=!${request}`)
|
|
71
73
|
}
|
|
72
74
|
}
|
package/lib/index.js
CHANGED
|
@@ -812,12 +812,24 @@ class MpxWebpackPlugin {
|
|
|
812
812
|
// 因为文件缓存的存在,前面hack identifier的行为对于从文件缓存中创建得到的module并不生效,因此需要在回调中进行二次hack处理
|
|
813
813
|
if (err) return rawCallback(err)
|
|
814
814
|
hackModuleIdentifier(module)
|
|
815
|
-
rawCallback(null, module)
|
|
815
|
+
return rawCallback(null, module)
|
|
816
816
|
}
|
|
817
817
|
}
|
|
818
818
|
return rawAddModule.call(compilation, module, callback)
|
|
819
819
|
}
|
|
820
820
|
|
|
821
|
+
// hack process https://github.com/webpack/webpack/issues/16045
|
|
822
|
+
const _handleModuleBuildAndDependenciesRaw = compilation._handleModuleBuildAndDependencies
|
|
823
|
+
|
|
824
|
+
compilation._handleModuleBuildAndDependencies = (originModule, module, recursive, callback) => {
|
|
825
|
+
const rawCallback = callback
|
|
826
|
+
callback = (err) => {
|
|
827
|
+
if (err) return rawCallback(err)
|
|
828
|
+
return rawCallback(null, module)
|
|
829
|
+
}
|
|
830
|
+
return _handleModuleBuildAndDependenciesRaw.call(compilation, originModule, module, recursive, callback)
|
|
831
|
+
}
|
|
832
|
+
|
|
821
833
|
const rawEmitAsset = compilation.emitAsset
|
|
822
834
|
|
|
823
835
|
compilation.emitAsset = (file, source, assetInfo) => {
|
|
@@ -929,7 +941,7 @@ class MpxWebpackPlugin {
|
|
|
929
941
|
}
|
|
930
942
|
})
|
|
931
943
|
|
|
932
|
-
|
|
944
|
+
const normalModuleFactoryParserCallback = (parser) => {
|
|
933
945
|
parser.hooks.call.for('__mpx_resolve_path__').tap('MpxWebpackPlugin', (expr) => {
|
|
934
946
|
if (expr.arguments[0]) {
|
|
935
947
|
const resource = expr.arguments[0].value
|
|
@@ -950,7 +962,7 @@ class MpxWebpackPlugin {
|
|
|
950
962
|
return true
|
|
951
963
|
})
|
|
952
964
|
|
|
953
|
-
const requireAsyncHandler = (expr, members) => {
|
|
965
|
+
const requireAsyncHandler = (expr, members, args) => {
|
|
954
966
|
if (members[0] === 'async') {
|
|
955
967
|
let request = expr.arguments[0].value
|
|
956
968
|
const range = expr.arguments[0].range
|
|
@@ -970,10 +982,10 @@ class MpxWebpackPlugin {
|
|
|
970
982
|
const dep = new CommonJsAsyncDependency(request, range)
|
|
971
983
|
parser.state.current.addDependency(dep)
|
|
972
984
|
}
|
|
985
|
+
if (args) parser.walkExpressions(args)
|
|
973
986
|
return true
|
|
974
987
|
} else {
|
|
975
988
|
compilation.errors.push(new Error(`The require async JS [${request}] need to declare subpackage name by root`))
|
|
976
|
-
return true
|
|
977
989
|
}
|
|
978
990
|
}
|
|
979
991
|
}
|
|
@@ -990,7 +1002,7 @@ class MpxWebpackPlugin {
|
|
|
990
1002
|
.tap({
|
|
991
1003
|
name: 'MpxWebpackPlugin',
|
|
992
1004
|
stage: -1000
|
|
993
|
-
}, (expr, calleeMembers, callExpr) => requireAsyncHandler(callExpr, calleeMembers))
|
|
1005
|
+
}, (expr, calleeMembers, callExpr) => requireAsyncHandler(callExpr, calleeMembers, expr.arguments))
|
|
994
1006
|
|
|
995
1007
|
// hack babel polyfill global
|
|
996
1008
|
parser.hooks.statementIf.tap('MpxWebpackPlugin', (expr) => {
|
|
@@ -1140,7 +1152,10 @@ class MpxWebpackPlugin {
|
|
|
1140
1152
|
parser.hooks.callMemberChain.for('mpx').tap('MpxWebpackPlugin', injectSrcModeForTransApi)
|
|
1141
1153
|
parser.hooks.callMemberChain.for('wx').tap('MpxWebpackPlugin', injectSrcModeForTransApi)
|
|
1142
1154
|
}
|
|
1143
|
-
}
|
|
1155
|
+
}
|
|
1156
|
+
normalModuleFactory.hooks.parser.for('javascript/auto').tap('MpxWebpackPlugin', normalModuleFactoryParserCallback)
|
|
1157
|
+
normalModuleFactory.hooks.parser.for('javascript/dynamic').tap('MpxWebpackPlugin', normalModuleFactoryParserCallback)
|
|
1158
|
+
normalModuleFactory.hooks.parser.for('javascript/esm').tap('MpxWebpackPlugin', normalModuleFactoryParserCallback)
|
|
1144
1159
|
|
|
1145
1160
|
// 为了正确生成sourceMap,将该步骤由原来的compile.hooks.emit迁移到compilation.hooks.processAssets
|
|
1146
1161
|
compilation.hooks.processAssets.tap({
|
package/lib/selector.js
CHANGED
|
@@ -3,17 +3,17 @@ const parseRequest = require('./utils/parse-request')
|
|
|
3
3
|
|
|
4
4
|
module.exports = function (content) {
|
|
5
5
|
this.cacheable()
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
|
|
7
|
+
// 移除mpx访问依赖,支持 thread-loader
|
|
8
|
+
const { mode, env } = this.getOptions() || {}
|
|
9
|
+
if (!mode && !env) {
|
|
9
10
|
return content
|
|
10
11
|
}
|
|
12
|
+
|
|
11
13
|
const { queryObj } = parseRequest(this.resource)
|
|
12
14
|
const ctorType = queryObj.ctorType
|
|
13
15
|
const type = queryObj.type
|
|
14
16
|
const index = queryObj.index || 0
|
|
15
|
-
const mode = mpx.mode
|
|
16
|
-
const env = mpx.env
|
|
17
17
|
const filePath = this.resourcePath
|
|
18
18
|
const parts = parseComponent(content, {
|
|
19
19
|
filePath,
|
package/lib/wxs/WxsPlugin.js
CHANGED
|
@@ -23,6 +23,14 @@ class WxsPlugin {
|
|
|
23
23
|
normalModuleFactory.hooks.parser
|
|
24
24
|
.for('javascript/auto')
|
|
25
25
|
.tap('WxsPlugin', handler)
|
|
26
|
+
|
|
27
|
+
normalModuleFactory.hooks.parser
|
|
28
|
+
.for('javascript/dynamic')
|
|
29
|
+
.tap('WxsPlugin', handler)
|
|
30
|
+
|
|
31
|
+
normalModuleFactory.hooks.parser
|
|
32
|
+
.for('javascript/esm')
|
|
33
|
+
.tap('WxsPlugin', handler)
|
|
26
34
|
})
|
|
27
35
|
}
|
|
28
36
|
}
|
|
@@ -1,6 +1,49 @@
|
|
|
1
1
|
const config = require('../config')
|
|
2
2
|
const { ConcatSource } = require('webpack').sources
|
|
3
3
|
const JavascriptModulesPlugin = require('webpack/lib/javascript/JavascriptModulesPlugin')
|
|
4
|
+
const RuntimeGlobals = require('webpack/lib/RuntimeGlobals')
|
|
5
|
+
const HelperRuntimeModule = require('webpack/lib/runtime/HelperRuntimeModule')
|
|
6
|
+
const Template = require('webpack/lib/Template')
|
|
7
|
+
|
|
8
|
+
class MakeNamespaceObjectRuntimeModule extends HelperRuntimeModule {
|
|
9
|
+
constructor () {
|
|
10
|
+
super('make namespace object')
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
generate () {
|
|
14
|
+
const { runtimeTemplate } = this.compilation
|
|
15
|
+
const fn = RuntimeGlobals.makeNamespaceObject
|
|
16
|
+
return Template.asString([
|
|
17
|
+
'// define __esModule on exports',
|
|
18
|
+
`${fn} = ${runtimeTemplate.basicFunction('exports', [
|
|
19
|
+
'exports.__esModule = true;'
|
|
20
|
+
])};`
|
|
21
|
+
])
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
class CompatGetDefaultExportRuntimeModule extends HelperRuntimeModule {
|
|
26
|
+
constructor () {
|
|
27
|
+
super('compat get default export')
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
generate () {
|
|
31
|
+
const { runtimeTemplate } = this.compilation
|
|
32
|
+
const fn = RuntimeGlobals.compatGetDefaultExport
|
|
33
|
+
return Template.asString([
|
|
34
|
+
'// getDefaultExport function for compatibility with non-harmony modules',
|
|
35
|
+
`${fn} = ${runtimeTemplate.basicFunction('module', [
|
|
36
|
+
'var getter = module && module.__esModule ?',
|
|
37
|
+
Template.indent([
|
|
38
|
+
`${runtimeTemplate.returningFunction('module["default"]')} :`,
|
|
39
|
+
`${runtimeTemplate.returningFunction('module')};`
|
|
40
|
+
]),
|
|
41
|
+
'getter.a = getter();',
|
|
42
|
+
'return getter;'
|
|
43
|
+
])};`
|
|
44
|
+
])
|
|
45
|
+
}
|
|
46
|
+
}
|
|
4
47
|
|
|
5
48
|
module.exports = class WxsTemplatePlugin {
|
|
6
49
|
constructor (options = { mode: 'wx' }) {
|
|
@@ -20,7 +63,34 @@ module.exports = class WxsTemplatePlugin {
|
|
|
20
63
|
return new ConcatSource(prefix, source)
|
|
21
64
|
})
|
|
22
65
|
|
|
23
|
-
//
|
|
66
|
+
// __webpack_require__.r
|
|
67
|
+
compilation.hooks.runtimeRequirementInTree
|
|
68
|
+
.for(RuntimeGlobals.makeNamespaceObject)
|
|
69
|
+
.tap({
|
|
70
|
+
name: 'WxsTemplatePlugin',
|
|
71
|
+
stage: -1000
|
|
72
|
+
}, chunk => {
|
|
73
|
+
compilation.addRuntimeModule(
|
|
74
|
+
chunk,
|
|
75
|
+
new MakeNamespaceObjectRuntimeModule()
|
|
76
|
+
)
|
|
77
|
+
return true
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
// __webpack_require__.n
|
|
81
|
+
compilation.hooks.runtimeRequirementInTree
|
|
82
|
+
.for(RuntimeGlobals.compatGetDefaultExport)
|
|
83
|
+
.tap({
|
|
84
|
+
name: 'WxsTemplatePlugin',
|
|
85
|
+
stage: -1000
|
|
86
|
+
}, chunk => {
|
|
87
|
+
compilation.addRuntimeModule(
|
|
88
|
+
chunk,
|
|
89
|
+
new CompatGetDefaultExportRuntimeModule()
|
|
90
|
+
)
|
|
91
|
+
return true
|
|
92
|
+
})
|
|
93
|
+
|
|
24
94
|
// mainTemplate.hooks.requireExtensions.tap(
|
|
25
95
|
// 'WxsMainTemplatePlugin',
|
|
26
96
|
// () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.46",
|
|
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": "5c8b46722d862bba145badd164c4675a43a577c3"
|
|
84
84
|
}
|