chore: more base configuration

This commit is contained in:
Igor Randjelovic
2020-11-19 21:45:16 +01:00
parent 4518cfa31b
commit 72a87c5d2c
18 changed files with 492 additions and 173 deletions

View File

@ -2,6 +2,7 @@ import Config from 'webpack-chain';
import webpack from 'webpack';
import { configs } from './configuration';
import { determineProjectFlavor } from './helpers/flavor';
import { highlight } from 'cli-highlight';
export type Platform = 'android' | 'ios' | string;
@ -17,14 +18,21 @@ export interface IWebpackEnv {
production?: boolean;
report?: boolean;
hmr?: boolean;
// enable verbose output
verbose?: boolean;
// todo: add others
}
let webpackChains: any[] = [];
let webpackMerges: any[] = [];
let env: IWebpackEnv = {};
let explicitUseConfig = false;
/**
* @internal
*/
export let env: IWebpackEnv = {};
////// PUBLIC API
export const defaultConfigs = configs;
@ -34,9 +42,11 @@ export function init(_env: IWebpackEnv) {
}
}
export function useConfig(config: keyof typeof defaultConfigs) {
export function useConfig(config: keyof typeof defaultConfigs | false) {
explicitUseConfig = true;
webpackChains.push(configs[config]);
if (config) {
webpackChains.unshift(configs[config]);
}
}
export function chainWebpack(chainFn: (config: Config, env: IWebpackEnv) => any) {
@ -59,6 +69,11 @@ export function resolveChainableConfig() {
return chainFn(config, env);
});
if (env.verbose) {
console.log('Resolved chainable config:');
console.log(highlight(config.toString(), { language: 'js' }));
}
return config;
}