GithubHelp home page GithubHelp logo

adamscybot / config-loader Goto Github PK

View Code? Open in Web Editor NEW

This project forked from webpack-contrib/config-loader

0.0 2.0 0.0 599 KB

A loader for webpack configuration files

License: MIT License

JavaScript 100.00%

config-loader's Introduction

npm node deps tests chat

config-loader

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.

Requirements

This module requires a minimum of Node v6.9.0 and Webpack v4.0.0.

Getting Started

To begin, you'll need to install config-loader:

$ npm install @webpack-contrib/config-loader --save-dev

And get straight to loading a config:

const loader = require('@webpack-contrib/config-loader');
const options = { ... };

loader(options).then((result) => {
  // ...
  // result = { config: Object, configPath: String }
});

Extending Configuration Files

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:

// base.config.js
module.exports = {
  name: 'base',
  mode: 'development',
  plugins: [...]
}
// webpack.config.js
module.exports = {
  extends: path.join(..., 'base-config.js'),
  name: 'dev'

The resulting configuration object would resemble:

// result
{
  name: 'dev',
  mode: 'development',
  plugins: [...]
}

The webpack.config.js file will be intelligently extended with properties from base.config.js.

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

Gotchas

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 in the env 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 env parameter. Rather, it makes calls with only the argv parameter.

Supported Compilers

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:

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.

API

loader([options])

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.

Options

allowMissing

Type: Boolean
Default: false

Instructs the module to allow a missing config file, and returns an Object with empty config and configPath properties in the event a config file was not found.

configPath

Type: String Default: undefined

Specifies an absolute path to a valid configuration file on the filesystem.

cwd

Type: String Default: process.cwd()

Specifies an filesystem path from which point config-loader will begin looking for a configuration file.

require

Type: String | Array[String] Default: undefined

Specifies compiler(s) to use when loading modules from files containing the configuration. For example:

const loader = require('@webpack-contrib/config-loader');
const options = { require: 'ts-node/register' };

loader(options).then((result) => { ... });

See Supported Compilers for more information.

schema

Type: Object Default: undefined

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.

Contributing

Please take a moment to read our contributing guidelines if you haven't yet done so.

License

config-loader's People

Contributors

ryanclark avatar shellscape avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.