Skip to content

Commit cd13b08

Browse files
authored
Merge branch 'master' into fix-rn-onAppHide
2 parents a9d773e + 7633097 commit cd13b08

4 files changed

Lines changed: 121 additions & 59 deletions

File tree

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
const Dependency = require('webpack/lib/Dependency')
2+
const makeSerializable = require('webpack/lib/util/makeSerializable')
3+
const ModuleDependency = require('webpack/lib/dependencies/ModuleDependency')
4+
const { RetryRuntimeGlobal } = require('./RetryRuntimeModule')
5+
6+
class ImportDependency extends ModuleDependency {
7+
/**
8+
* @param {string} request the request
9+
* @param {[number, number]} range expression range
10+
* @param {string[][]=} referencedExports list of referenced exports
11+
*/
12+
constructor (request, range, referencedExports, extraOptions) {
13+
super(request)
14+
this.range = range
15+
this.referencedExports = referencedExports
16+
this.extraOptions = extraOptions
17+
}
18+
19+
get type () {
20+
return 'import()'
21+
}
22+
23+
get category () {
24+
return 'esm'
25+
}
26+
27+
/**
28+
* Returns list of exports referenced by this dependency
29+
* @param {ModuleGraph} moduleGraph module graph
30+
* @param {RuntimeSpec} runtime the runtime for which the module is analysed
31+
* @returns {(string[] | ReferencedExport)[]} referenced exports
32+
*/
33+
getReferencedExports (moduleGraph, runtime) {
34+
return this.referencedExports
35+
? this.referencedExports.map((e) => ({
36+
name: e,
37+
canMangle: false
38+
}))
39+
: Dependency.EXPORTS_OBJECT_REFERENCED
40+
}
41+
42+
serialize (context) {
43+
context.write(this.range)
44+
context.write(this.referencedExports)
45+
context.write(this.extraOptions)
46+
super.serialize(context)
47+
}
48+
49+
deserialize (context) {
50+
this.range = context.read()
51+
this.referencedExports = context.read()
52+
this.extraOptions = context.read()
53+
super.deserialize(context)
54+
}
55+
}
56+
57+
makeSerializable(ImportDependency, '@mpxjs/webpack-plugin/lib/dependencies/ImportDependency')
58+
59+
ImportDependency.Template = class ImportDependencyTemplate extends (
60+
ModuleDependency.Template
61+
) {
62+
/**
63+
* @param {Dependency} dependency the dependency for which the template should be applied
64+
* @param {ReplaceSource} source the current replace source which can be modified
65+
* @param {DependencyTemplateContext} templateContext the context object
66+
* @returns {void}
67+
*/
68+
apply (
69+
dependency,
70+
source,
71+
{ runtimeTemplate, module, moduleGraph, chunkGraph, runtimeRequirements }
72+
) {
73+
const dep = /** @type {ImportDependency} */ (dependency)
74+
const block = /** @type {AsyncDependenciesBlock} */ (
75+
moduleGraph.getParentBlock(dep)
76+
)
77+
let content = runtimeTemplate.moduleNamespacePromise({
78+
chunkGraph,
79+
block: block,
80+
module: /** @type {Module} */ (moduleGraph.getModule(dep)),
81+
request: dep.request,
82+
strict: /** @type {BuildMeta} */ (module.buildMeta).strictHarmonyModule,
83+
message: 'import()',
84+
runtimeRequirements
85+
})
86+
// replace fakeType by 9 to fix require.async to commonjs2 module like 'module.exports = function(){...}'
87+
content = content.replace(/(__webpack_require__\.t\.bind\(.+,\s*)(\d+)(\s*\))/, (_, p1, p2, p3) => {
88+
return p1 + '9' + p3
89+
})
90+
91+
// require.async 的场景且配置了重试次数才注入 RetryRuntimeModule
92+
const extraOptions = dep.extraOptions || {}
93+
if (extraOptions.isRequireAsync && extraOptions.retryRequireAsync && extraOptions.retryRequireAsync.times > 0) {
94+
runtimeRequirements.add(RetryRuntimeGlobal)
95+
content = `${RetryRuntimeGlobal}(function() { return ${content} }, ${extraOptions.retryRequireAsync.times}, ${extraOptions.retryRequireAsync.interval})`
96+
}
97+
98+
source.replace(dep.range[0], dep.range[1] - 1, content)
99+
}
100+
}
101+
102+
module.exports = ImportDependency

packages/webpack-plugin/lib/dependencies/ImportDependencyTemplate.js

Lines changed: 0 additions & 50 deletions
This file was deleted.

packages/webpack-plugin/lib/index.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ const EntryPlugin = require('webpack/lib/EntryPlugin')
1414
const JavascriptModulesPlugin = require('webpack/lib/javascript/JavascriptModulesPlugin')
1515
const FlagEntryExportAsUsedPlugin = require('webpack/lib/FlagEntryExportAsUsedPlugin')
1616
const FileSystemInfo = require('webpack/lib/FileSystemInfo')
17-
const ImportDependency = require('webpack/lib/dependencies/ImportDependency')
18-
const ImportDependencyTemplate = require('./dependencies/ImportDependencyTemplate')
17+
const ImportDependency = require('./dependencies/ImportDependency')
1918
const AsyncDependenciesBlock = require('webpack/lib/AsyncDependenciesBlock')
2019
const ProvidePlugin = require('webpack/lib/ProvidePlugin')
2120
const normalize = require('./utils/normalize')
@@ -698,7 +697,8 @@ class MpxWebpackPlugin {
698697
compilation.dependencyFactories.set(RequireExternalDependency, new NullFactory())
699698
compilation.dependencyTemplates.set(RequireExternalDependency, new RequireExternalDependency.Template())
700699

701-
compilation.dependencyTemplates.set(ImportDependency, new ImportDependencyTemplate())
700+
compilation.dependencyFactories.set(ImportDependency, normalModuleFactory)
701+
compilation.dependencyTemplates.set(ImportDependency, new ImportDependency.Template())
702702
})
703703

704704
compiler.hooks.thisCompilation.tap('MpxWebpackPlugin', (compilation, { normalModuleFactory }) => {
@@ -1453,18 +1453,17 @@ class MpxWebpackPlugin {
14531453
if (mpx.supportRequireAsync) {
14541454
if (isWeb(mpx.mode) || isReact(mpx.mode)) {
14551455
if (isReact(mpx.mode)) tarRoot = transSubpackage(mpx.transSubpackageRules, tarRoot)
1456-
request = addQuery(request, {
1457-
isRequireAsync: true,
1458-
retryRequireAsync: JSON.stringify(this.options.retryRequireAsync)
1459-
})
14601456
const depBlock = new AsyncDependenciesBlock(
14611457
{
14621458
name: tarRoot + '/index'
14631459
},
14641460
expr.loc,
14651461
request
14661462
)
1467-
const dep = new ImportDependency(request, expr.range)
1463+
const dep = new ImportDependency(request, expr.range, undefined, {
1464+
isRequireAsync: true,
1465+
retryRequireAsync: this.options.retryRequireAsync
1466+
})
14681467
dep.loc = expr.loc
14691468
depBlock.addDependency(dep)
14701469
parser.state.current.addBlock(depBlock)

packages/webpack-plugin/lib/runtime/components/web/mpx-video.vue

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@
148148
},
149149
controls: function (show) {
150150
this.$emit('controlstoggle', inheritEvent('controlstoggle', {}, { show }))
151+
},
152+
objectFit (val) {
153+
if (this._player && this._player.video) {
154+
this._player.video.style.objectFit = val
155+
}
151156
}
152157
},
153158
mounted () {
@@ -189,6 +194,9 @@
189194
if (this.initialTime) {
190195
this._player.seek(this.initialTime)
191196
}
197+
if (this.objectFit) {
198+
this._player.video.style.objectFit = this.objectFit
199+
}
192200
},
193201
initStyle () {
194202
@@ -239,7 +247,10 @@
239247
240248
this._player.on('progress', (e) => {
241249
const eNode = e.target
242-
const buffered = (eNode?.buffered?.end(0)) / (eNode?.duration)
250+
let buffered = 0
251+
if (eNode?.buffered && eNode.buffered.length > 0) {
252+
buffered = (eNode.buffered.end(0)) / (eNode?.duration)
253+
}
243254
this.$emit('progress', inheritEvent('progress', e, { buffered: buffered * 100 }))
244255
})
245256

0 commit comments

Comments
 (0)