mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-14 18:12:09 +08:00
feat: external config loading
+refactor many pieces
This commit is contained in:
36
packages/webpack5/src/helpers/externalConfigs.ts
Normal file
36
packages/webpack5/src/helpers/externalConfigs.ts
Normal file
@ -0,0 +1,36 @@
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
import dedent from 'ts-dedent';
|
||||
import * as lib from '../index';
|
||||
import { error, info } from './log';
|
||||
import { getAllDependencies, getDependencyPath } from './dependencies';
|
||||
|
||||
export function applyExternalConfigs() {
|
||||
getAllDependencies().forEach((dependency) => {
|
||||
const packagePath = getDependencyPath(dependency);
|
||||
const configPath = path.join(packagePath, 'nativescript.webpack.js');
|
||||
|
||||
if (fs.existsSync(configPath)) {
|
||||
info(`Discovered config: ${configPath}`);
|
||||
|
||||
try {
|
||||
const externalConfig = require(configPath);
|
||||
|
||||
if (typeof externalConfig === 'function') {
|
||||
externalConfig(lib);
|
||||
} else {
|
||||
// todo: warn user
|
||||
// todo: perhaps support exported objects to merge into config?
|
||||
}
|
||||
} catch (err) {
|
||||
error(
|
||||
dedent`
|
||||
Unable to apply config: ${configPath}.
|
||||
Error is:
|
||||
`,
|
||||
err
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user