A webpack configuration loader
npm install @webpack-contrib/config-loader[![npm][npm]][npm-url]
[![node][node]][node-url]
[![deps][deps]][deps-url]
[![tests][tests]][tests-url]
[![chat][chat]][chat-url]
A webpack configuration loader.
This module utilizes cosmiconfig
which supports declaring a webpack configuration in a number of different file
formats including; .webpackrc, webpack.config.js, and a webpack property
in a package.json.
config-loader supports configuration modules which export an Object, Array,Function, Promise, and Function which returns a Promise.
The module also validates found configurations against webpack's options schema
to ensure that the configuration is correct before webpack attempts to use it.
This module requires a minimum of Node v6.9.0 and Webpack v4.0.0.
To begin, you'll need to install config-loader:
``console`
$ npm install @webpack-contrib/config-loader --save-dev
And get straight to loading a config:
`js
const loader = require('@webpack-contrib/config-loader');
const options = { ... };
loader(options).then((result) => {
// ...
// result = { config: Object, configPath: String }
});
`
This module supports extending webpack configuration files with
ESLint-style
extends functionality. This feature allows users to create a "base" config and
in essence, "inherit" from that base config in a separate config. A bare-bones
example:
`js`
// base.config.js
module.exports = {
name: 'base',
mode: 'development',
plugins: [...]
}
`js`
// webpack.config.js
module.exports = {
extends: path.join(..., 'base-config.js'),
name: 'dev'
The resulting configuration object would resemble:
`js`
// result
{
name: 'dev',
mode: 'development',
plugins: [...]
}
The webpack.config.js file will be intelligently extended with propertiesbase.config.js
from .
The extends property also supports naming installed NPM modules which export
webpack configurations. Various configuration properties can also be filtered in
different ways based on need.
Read More about Extending Configuration Files
When using a configuration file that exports a Function, users of webpack-cli
have become accustom to the function signature:
``
function config (env, argv)
webpack-cli provides any CLI flags prefixed with --env as a single object inenv
the parameter, which is an unnecessary feature.
Environment Variables
have long served the same purpose, and are easily accessible within a
Node environment.
As such, config-loader does not call Function configs with the envargv
parameter. Rather, it makes calls with only the parameter.
This module can support non-standard JavaScript file formats when a compatible
compiler is registered via the require option. If the option is defined,config-loader will attempt to require the specified module(s) before the
target config is found and loaded.
As such, config-loader will also search for the following file extensions;.js, .es6, .flow, .mjs, and .ts.
The module is also tested with the following compilers:
- babel-register
- flow-remove-types/register
- ts-node/register
_Note: Compilers are not part of or built-into this module. To use a specific compiler, you
must install it and specify its use by using the --require CLI flag._
Returns a Promise, which resolves with an Object containing:
#### config
Type: Object
Contains the actual configuration object.
#### configPath
Type: String
Contains the full, absolute filesystem path to the configuration file.
#### allowMissing
Type: Boolean false
Default:
Instructs the module to allow a missing config file, and returns an Objectconfig
with empty and configPath properties in the event a config file was
not found.
Type: Stringundefined
Default:
Specifies an absolute path to a valid configuration file on the filesystem.
Type: Stringprocess.cwd()
Default:
Specifies an filesystem path from which point config-loader will begin looking
for a configuration file.
Type: String | Array[String]undefined
Default:
Specifies compiler(s) to use when loading modules from files containing the
configuration. For example:
`js
const loader = require('@webpack-contrib/config-loader');
const options = { require: 'ts-node/register' };
loader(options).then((result) => { ... });
`
See
Supported Compilers
for more information.
Type: Objectundefined
Default:
An object containing a valid
JSON Schema Definition.
By default, config-loader` validates your webpack config against the
webpack config schema.
However, it can be useful to append additional schema data to allow configs,
which contain properties not present in the webpack schema, to pass validation.
Please take a moment to read our contributing guidelines if you haven't yet done so.
#### CONTRIBUTING
#### MIT
[npm]: https://img.shields.io/npm/v/@webpack-contrib/config-loader.svg
[npm-url]: https://npmjs.com/package/@webpack-contrib/config-loader
[node]: https://img.shields.io/node/v/@webpack-contrib/config-loader.svg
[node-url]: https://nodejs.org
[deps]: https://david-dm.org/webpack-contrib/config-loader.svg
[deps-url]: https://david-dm.org/webpack-contrib/config-loader
[tests]: https://img.shields.io/circleci/project/github/webpack-contrib/config-loader.svg
[tests-url]: https://circleci.com/gh/webpack-contrib/config-loader
[cover]: https://codecov.io/gh/webpack-contrib/config-loader/branch/master/graph/badge.svg
[cover-url]: https://codecov.io/gh/webpack-contrib/config-loader
[chat]: https://img.shields.io/badge/gitter-webpack%2Fwebpack-brightgreen.svg
[chat-url]: https://gitter.im/webpack/webpack