diff --git a/packages/webpack5/src/helpers/externalConfigs.ts b/packages/webpack5/src/helpers/externalConfigs.ts index b355a5c49..94f11bf05 100644 --- a/packages/webpack5/src/helpers/externalConfigs.ts +++ b/packages/webpack5/src/helpers/externalConfigs.ts @@ -3,6 +3,7 @@ import fs from 'fs'; import { getAllDependencies, getDependencyPath } from './dependencies'; import { clearCurrentPlugin, setCurrentPlugin } from '../index'; +import { tryRequireThenImport } from './dynamicImports'; import { info, warn } from './log'; import * as lib from '../index'; @@ -17,13 +18,20 @@ export async function applyExternalConfigs() { continue; } - const configPath = path.join(packagePath, 'nativescript.webpack.js'); + const configPaths = [ + path.join(packagePath, 'nativescript.webpack.mjs'), + path.join(packagePath, 'nativescript.webpack.js'), + ]; - if (fs.existsSync(configPath)) { + const configPath = configPaths.find((_configPath) => + fs.existsSync(_configPath) + ); + + if (configPath) { info(`Discovered config: ${configPath}`); setCurrentPlugin(dependency); try { - const externalConfig = require(configPath); + const externalConfig = await tryRequireThenImport(configPath); if (typeof externalConfig === 'function') { info('Applying external config...');