Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Make rule.include, rule.exclude, loaders and plugins more extensible #16

Merged
merged 1 commit into from
Mar 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 106 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ This is easier explained through the examples following.

## Contributing

I welcome any contributor. Just fork and clone, make changes, and send a pull request.
We welcome any contributor. Just fork and clone, make changes, and send a pull request.

## Installation

Expand Down Expand Up @@ -73,26 +73,36 @@ config.module
.rule('lint')
.test(/\.js$/)
.pre()
.include('src')
// Even create named loaders for later modification
.loader('eslint', 'eslint-loader', {
rules: {
semi: 'off'
}
});
.include
.add('src')
.end()
// Even create named uses (loaders) for later modification
.use('eslint')
.loader('eslint-loader')
.options({
rules: {
semi: 'off'
}
});

config.module
.rule('compile')
.test(/\.js$/)
.include('src', 'test')
.loader('babel', 'babel-loader', {
presets: [
['babel-preset-es2015', { modules: false }]
]
});
.include
.add('src')
.add('test')
.end()
.use('babel')
.loader('babel-loader')
.options({
presets: [
['babel-preset-es2015', { modules: false }]
]
});

// Create named plugins, too!
config.plugin('clean', CleanPlugin, [BUILD], { root: CWD });
config.plugin('clean')
.use(CleanPlugin, [['dist'], { root: '/dir' }]);

// Export the completed configuration object to be consumed by webpack
module.exports = config.toConfig();
Expand Down Expand Up @@ -513,40 +523,84 @@ config.performance
.assetFilter(assetFilter)
```

#### Config plugins

```js
// Backed at config.plugins
config.plugin(name) : ChainedMap
```

#### Config plugins: adding

_NOTE: Do not use `new` to create the plugin, as this will be done for you._

```js
// Backed at config.plugins
config.plugin(name, WebpackPlugin, ...args) : chainable
config
.plugin(name)
.use(WebpackPlugin, args)

// Example
config.plugin('env', webpack.EnvironmentPlugin, 'NODE_ENV');
// Examples
config
.plugin('hot')
.use(webpack.HotModuleReplacementPlugin);

config
.plugin('env')
.use(webpack.EnvironmentPlugin, ['NODE_ENV']);
```

#### Config plugins: modifying arguments
#### Config plugins: modify arguments

```js
config.plugin(name, args => newArgs)
config
.plugin(name)
.tap(args => newArgs)

// Example
config.plugin('env', args => [...args, 'SECRET_KEY']);
config
.plugin('env')
.tap(args => [...args, 'SECRET_KEY']);
```

#### Config plugins: modify instantiation

```js
config
.plugin(name)
.init((Plugin, args) => new Plugin(...args));
```

#### Config resolve plugins

```js
// Backed at config.plugins
config.resolve.plugin(name) : ChainedMap
```

#### Config resolve plugins: adding

_NOTE: Do not use `new` to create the plugin, as this will be done for you._

```js
// Backed at config.resolve.plugins
config.resolve.plugin(name, WebpackPlugin, ...args) : chainable
config.resolve
.plugin(name)
.use(WebpackPlugin, args)
```

#### Config resolve plugins: modifying arguments
#### Config plugins: modify arguments

```js
config.resolve.plugin(name, args => newArgs)
config.resolve
.plugin(name)
.tap(args => newArgs)
```

#### Config plugins: modify instantiation

```js
config.resolve
.plugin(name)
.init((Plugin, args) => new Plugin(...args))
```

#### Config node
Expand Down Expand Up @@ -607,38 +661,43 @@ config.module
.test(test)
.pre()
.post()
.include(...paths)
.exclude(...paths)
.enforce(preOrPost)
```

#### Config module rules loaders: creating
#### Config module rules uses (loaders): creating

```js
config.module.rules[].loaders : Map
config.module.rules{}.uses : ChainedMap

config.module
.rule(name)
.loader(name, loader, options: optional)
.use(name)
.loader(loader)
.options(options)

// Example

config.module
.rule('compile')
.loader('babel', 'babel-loader', { presets: ['babel-preset-es2015'] });
.use('babel')
.loader('babel-loader')
.options({ presets: ['babel-preset-es2015'] });
```

#### Config module rules loaders: modifying options
#### Config module rules uses (loaders): modifying options

```js
config.module
.rule(name)
.loader(name, options => newOptions)

.use(name)
.tap(options => newOptions)

// Example

config.module
.rule('compile')
.loader('babel', options => merge(options, { plugins: ['babel-plugin-object-rest-spread'] }));
.use('babel')
.tap(options => merge(options, { plugins: ['babel-plugin-syntax-object-rest-spread'] }));
```

---
Expand Down Expand Up @@ -717,7 +776,12 @@ config.merge({
},

performance: {
[key]: value
[key]: value,

hints,
maxEntrypointSize,
maxAssetSize,
assetFilter
},

resolve: {
Expand Down Expand Up @@ -757,12 +821,14 @@ config.merge({
[name]: {
[key]: value,

enforce,
test,
parser,

include: [...paths],
exclude: [...paths],
test: RegExp,
enforce: value,

loader: {
use: {
[name]: {
loader: LoaderString,
options: LoaderOptions
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "webpack-chain",
"version": "2.0.1",
"version": "3.0.0",
"main": "src/Config.js",
"repository": "mozilla-neutrino/webpack-chain",
"keywords": [
Expand Down
16 changes: 8 additions & 8 deletions src/ChainedMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const Chainable = require('./Chainable');
module.exports = class extends Chainable {
constructor(parent) {
super(parent);
this.options = new Map();
this.store = new Map();
}

extend(methods) {
Expand All @@ -14,17 +14,17 @@ module.exports = class extends Chainable {
}

clear() {
this.options.clear();
this.store.clear();
return this;
}

delete(key) {
this.options.delete(key);
this.store.delete(key);
return this;
}

entries() {
const entries = [...this.options];
const entries = [...this.store];

if (!entries.length) {
return;
Expand All @@ -37,19 +37,19 @@ module.exports = class extends Chainable {
}

values() {
return [...this.options.values()];
return [...this.store.values()];
}

get(key) {
return this.options.get(key);
return this.store.get(key);
}

has(key) {
return this.options.has(key);
return this.store.has(key);
}

set(key, value) {
this.options.set(key, value);
this.store.set(key, value);
return this;
}

Expand Down
16 changes: 8 additions & 8 deletions src/ChainedSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,39 @@ const Chainable = require('./Chainable');
module.exports = class extends Chainable {
constructor(parent) {
super(parent);
this.collection = new Set();
this.store = new Set();
}

add(value) {
this.collection.add(value);
this.store.add(value);
return this;
}

prepend(value) {
this.collection = new Set([value, ...this.collection]);
this.store = new Set([value, ...this.store]);
return this;
}

clear() {
this.collection.clear();
this.store.clear();
return this;
}

delete(value) {
this.collection.delete(value);
this.store.delete(value);
return this;
}

values() {
return [...this.collection];
return [...this.store];
}

has(value) {
return this.collection.has(value);
return this.store.has(value);
}

merge(arr) {
this.collection = new Set([...this.collection, ...arr]);
this.store = new Set([...this.store, ...arr]);
return this;
}
};
Loading