Extensible configuration plugin system that provides validation, change handling, and extensibility for all user configuration options in af-webpack.
Get available configuration plugins for validation and customization of user configuration options.
/**
* Get available configuration plugins
* @returns Array of configuration plugin objects
*/
function getUserConfigPlugins(): ConfigPlugin[];
interface ConfigPlugin {
name: string;
validate?: (value: any) => void;
onChange?: (change: ConfigChange) => void;
}
interface ConfigChange {
name: string; // Configuration option name
val: any; // Previous value
newVal: any; // New value
config: object; // Previous complete configuration
newConfig: object; // New complete configuration
}Usage Examples:
const getUserConfigPlugins = require('af-webpack/getUserConfigPlugins');
// Get all available configuration plugins
const plugins = getUserConfigPlugins();
console.log('Available config options:', plugins.map(p => p.name));
// Example plugin structure
plugins.forEach(plugin => {
console.log(`Plugin: ${plugin.name}`);
if (plugin.validate) {
console.log(' - Has validation');
}
if (plugin.onChange) {
console.log(' - Has change handler');
}
});entry
object | stringoutputPath
string'dist'publicPath
stringhash
booleanfalsebabel
objectextraBabelPresets
string[]extraBabelPlugins
string[]extraBabelIncludes
(string | Function)[]typescript
objecttsConfigFile
stringdisableDynamicImport
booleanfalsetheme
objectlessLoaderOptions
objectsass
objectstylus
objectautoprefixer
objectextraPostCSSPlugins
object[]cssModulesExcludes
string[]cssModulesWithAffix
booleanfalsedisableCSSModules
booleanfalsedisableCSSSourceMap
booleanfalsecssLoaderVersion
stringcssLoaderOptions
objectcssPublicPath
stringstyleLoader
objectcssnano
objectdevServer
objectdevtool
stringproxy
objectalias
objectcopy
string | object | (string | object)[]externals
objecturlLoaderExcludes
string[]minimizer
'uglifyjs' | 'terserjs'uglifyJSOptions
objectterserJSOptions
objectignoreMomentLocale
booleanfalsedefine
objectchainConfig
functionbrowserslist
string[]manifest
objectgenerateCssModulesTypings
booleanfalsees5ImcompatibleVersions
string[]env
objectEach plugin provides validation to ensure configuration correctness:
// Example validation error handling
try {
const { config } = getUserConfig({
// Invalid configuration
minimizer: 'invalid-minimizer'
});
} catch (error) {
console.error(error.message);
// "Configuration item minimizer must be 'uglifyjs' or 'terserjs'"
}Plugins can define custom behavior when configuration changes:
While not typically needed, the plugin system is designed for extensibility. Each plugin exports a function returning plugin configuration:
// Example plugin structure
export default function() {
return {
name: 'customOption',
validate(value) {
if (typeof value !== 'string') {
throw new Error('customOption must be a string');
}
},
onChange({ name, val, newVal, config, newConfig }) {
console.log(`${name} changed from ${val} to ${newVal}`);
// Handle configuration change
}
};
}