webpack-tools
A collection of helpers to make maintaining a
webpack
config a little easier.
loader
Provides a fluent interface for the loader syntax:
const jsloader =
would be the same as writing:
const jsloader = test: /^.*\.js$/ loader: 'eslint-loader?{"emitError":false,"configFile":"./eslintrc"}!babel-loader' include: /^\/Users\/romeovs\/code\/webpack-tools\/src\/.*$/ exclude: /^node_modules\/.*$/ ;
The main differences are:
loader
allows glob syntax instead of plain regexes (which are also supported) for specifyingtest
,includes
andexcludes
.- This api makes more use of primitive datastructures instead of strings.
(look at the options passed to the
eslint
loader. - Every loader object is immutable, so every call to one of its
methods returns a new loader. This makes it easy to extend loaders
without much confusion:const base = // ...const lint = base // ...const babel = base // ...
- You can only create a loader by calling
test
.
merge
Provides an easy way to merge several partial configs. This is just a simple function that recursivly merges mixed datastructures (consisting of arrays and objects).
production
Check wether or not we are in production mode.
Checks if the -p
or --optimize-minize
flags are set or
if the NODE_ENV
is set to production
.
clean
Cleans falsy plugins from a config so we can write code like this:
const conf = /* ... */ plugins: production ? bar baz : false