@@ -3,7 +3,7 @@ const { mergeConfig } = require('metro-config')
33const { fse, ejs, tapable : { SyncHook, SyncBailHook } , log, paths : ps , dataExtend, argv } = require ( 'general-tools' )
44const baseConfig = require ( './config/baseConfig' )
55const InjectVar = require ( './plugins/InjectVar' )
6- const { isBaseDllPath, paths, dllJsonName, output, replacePath } = require ( './utils' )
6+ const { isBaseDllPath, paths, dllJsonName, output, replacePath, preName } = require ( './utils' )
77const { BuildType } = require ( './types' )
88const pkg = require ( '../package.json' )
99
@@ -194,18 +194,60 @@ class MetroCodeSplit {
194194 * @returns { boolean }
195195 */
196196 isDllPath = p => {
197+ let prePaths = [ ]
197198 let commonPaths = [ ]
199+ const preRefPath = path . resolve ( ps . cwdDir , path . join ( this . options . dll . referenceDir , preName ) )
200+ const dllRefPath = path . resolve ( ps . cwdDir , path . join ( this . options . dll . referenceDir , dllJsonName ) )
201+ try {
202+ prePaths = require ( preRefPath )
203+ } catch ( err ) {
204+ ! this . isBuildDllJson && log ( 'warning: failed to load the preRefPath correctly! are you setting the "dll.referenceDir" correctly?' , 'yellow' )
205+ }
198206 try {
199- const dllRefPath = path . resolve ( ps . cwdDir , path . join ( this . options . dll . referenceDir , dllJsonName ) )
200207 commonPaths = require ( dllRefPath )
201208 } catch ( err ) {
202- BuildType . DllJson !== this . bundleOutputInfo . name && log ( 'warning: failed to load the dllRefPath correctly! are you setting the "dll.referenceDir" correctly?' , 'yellow' )
209+ ! this . isBuildDllJson && log ( 'warning: failed to load the dllRefPath correctly! are you setting the "dll.referenceDir" correctly?' , 'yellow' )
203210 }
204211 // inertia method
205- this . isDllPath = p => commonPaths . includes ( replacePath ( p ) )
212+ this . isDllPath = ap => {
213+ const rp = replacePath ( ap )
214+ // iife section contains | __d ===
215+ return prePaths . some ( v => rp . endsWith ( v ) || v . endsWith ( rp ) ) || commonPaths . includes ( rp )
216+ }
206217 return this . isDllPath ( p )
207218 }
208219
220+ /**
221+ * @param { string } p absolute path
222+ * @returns { string }
223+ */
224+ findDllModuleId = p => {
225+ let prePaths = [ ]
226+ let commonPaths = [ ]
227+ const preRefPath = path . resolve ( ps . cwdDir , path . join ( this . options . dll . referenceDir , preName ) )
228+ const dllRefPath = path . resolve ( ps . cwdDir , path . join ( this . options . dll . referenceDir , dllJsonName ) )
229+ try {
230+ prePaths = require ( preRefPath )
231+ } catch ( err ) {
232+ ! this . isBuildDllJson && log ( 'warning: failed to load the preRefPath correctly! are you setting the "dll.referenceDir" correctly?' , 'yellow' )
233+ }
234+ try {
235+ commonPaths = require ( dllRefPath )
236+ } catch ( err ) {
237+ ! this . isBuildDllJson && log ( 'warning: failed to load the dllRefPath correctly! are you setting the "dll.referenceDir" correctly?' , 'yellow' )
238+ }
239+ // inertia method
240+ this . findDllModuleId = ap => {
241+ const rp = replacePath ( ap )
242+ const iifeId = prePaths . find ( v => rp . endsWith ( v ) || v . endsWith ( rp ) )
243+ if ( iifeId ) return iifeId
244+ const dId = commonPaths . find ( v => v === rp )
245+ if ( dId ) return dId
246+ throw new Error ( 'failed to find the dll module id!' )
247+ }
248+ return this . findDllModuleId ( p )
249+ }
250+
209251 async mergeTo ( busineConfig ) {
210252 if ( ! require ( './utils' ) . isProduction ) {
211253 log (
@@ -243,6 +285,10 @@ class MetroCodeSplit {
243285 get isBuildDll ( ) {
244286 return [ BuildType . DllJson , BuildType . Dll ] . includes ( this . bundleOutputInfo . name )
245287 }
288+
289+ get isBuildDllJson ( ) {
290+ return BuildType . DllJson === this . bundleOutputInfo . name
291+ }
246292}
247293
248294module . exports = MetroCodeSplit
0 commit comments