feat: support mjs external configs

This commit is contained in:
Igor Randjelovic
2021-11-21 18:47:25 +01:00
parent f21c45f67d
commit 4e7ec4e9a5

View File

@ -3,6 +3,7 @@ import fs from 'fs';
import { getAllDependencies, getDependencyPath } from './dependencies'; import { getAllDependencies, getDependencyPath } from './dependencies';
import { clearCurrentPlugin, setCurrentPlugin } from '../index'; import { clearCurrentPlugin, setCurrentPlugin } from '../index';
import { tryRequireThenImport } from './dynamicImports';
import { info, warn } from './log'; import { info, warn } from './log';
import * as lib from '../index'; import * as lib from '../index';
@ -17,13 +18,20 @@ export async function applyExternalConfigs() {
continue; 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}`); info(`Discovered config: ${configPath}`);
setCurrentPlugin(dependency); setCurrentPlugin(dependency);
try { try {
const externalConfig = require(configPath); const externalConfig = await tryRequireThenImport(configPath);
if (typeof externalConfig === 'function') { if (typeof externalConfig === 'function') {
info('Applying external config...'); info('Applying external config...');