@mpxjs/webpack-plugin 2.7.44 → 2.7.45
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/wxs/WxsTemplatePlugin.js +71 -1
- package/package.json +2 -2
|
@@ -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.45",
|
|
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": "ff14a937249fc63600157388d80650d6986d7cb8"
|
|
84
84
|
}
|