@webpack-blocks/webpack2
Advanced tools
Webpack block for the webpack 2.x base configuration.
Weekly downloads
Changelog
v0.4 - A lot of small improvements
Another step towards v1.0, containing one potentially breaking change:
The default CSS loader does not exclude the node_modules/
directory anymore. So you can now just require('some-other-package/stylesheet.css')
without additional configuration.
As the 1.0 release is getting closer I would like to encourage you to provide feedback, so we get to know what works well and what has to be improved.
Please share your experiences when using webpack-blocks, no matter if you encounter any problems or everything worked just fine right away! 👍
Just open your package.json
and upgrade the @webpack-blocks/*
dependencies to ^0.4.0
. Then run npm install
/ yarn
.
Make sure you update all webpack-block packages at once, since the new default CSS loader behavior made changes in css-modules
and postcss
blocks necessary as well.
node_modules/
anymorecreateConfig.vanilla()
(#80, #95)dev-server
composable (#78)Under the hood:
webpackVersion
to context
webpack-merge
v2.3 instead of v0.14webpack
v2.2 instead of the RC (webpack2
and related blocks only, of course)application/x-typescript
file typetext/x-less
file typeLooking for TypeScript support? Then there is good news: @jvanbruegge just added the typescript and tslint blocks.
Check 'em out if you would like to give static typing a try 😉
Readme
This is the webpack2
block providing webpack 2 core functionality. Also provides all @webpack-blocks/core
exports for convenience.
const HtmlWebpackPlugin = require('html-webpack-plugin')
const { addPlugins, createConfig, entryPoint, env, setOutput, sourceMaps, webpack } = require('@webpack-blocks/webpack2')
module.exports = createConfig([
entryPoint('./src/main.js'),
setOutput('./build/bundle.js'),
addPlugins([
new HtmlWebpackPlugin({
inject: true,
template: './index.html'
}),
new webpack.DefinePlugin({
'process.env': JSON.stringify(process.env || 'development')
})
]),
env('development', [
// will only enable source maps if `NODE_ENV === 'development'`
sourceMaps()
])
])
There are some webpack loaders and plugins that are only compatible with webpack 2 in a certain version. Make sure you use the appropriate webpack blocks:
Takes an array of config setters (the functions returned by invoked webpack blocks), invokes them and returns the resulting webpack config object. Already sets some generic default config, like default CSS, font and image file loaders.
Works just like createConfig()
, but provides no default configuration whatsoever. Use it only if you want to get rid of the default loaders for some reason.
Combines an array of blocks to a new joined block. Running this single block has the same effect as running all source blocks.
Applies an array of webpack blocks only if process.env.NODE_ENV
matches the given envName
. If no NODE_ENV
is set, it will be treated as 'development'.
Replaces constants in your source code with a value (process.env.NODE_ENV
for example) using the webpack.DefinePlugin. Pass an object containing your constant definitions: { [constantName: string]: <constantValue: any> }
.
Every constant's value is JSON.stringify()
-ed first, so you don't have to remember.
Special feature: Using defineConstants
multiple times results in a single DefinePlugin instance configured to do all the replacements.
Same as require('webpack')
.
Add custom plugins to the webpack configuration.
Example usage: addPlugins([ new HtmlWebpackPlugin() ])
Add some custom configuration to the webpack configuration. The object you pass will be merged into the webpack configuration object.
Adds one or multiple entry points. If the parameter is not an object the entry point(s) will be added to the default chunk named main
. This way we make sure that the resulting https://webpack.github.io/docs/configuration.html#entry configuration property will always be an object.
Set a performance budget. Performance budgets are custom limits (like max bundle size) you can set to make webpack warn you or throw an error if the application exceeds those limits.
Options object:
{
maxAssetSize: number, // File size limit in bytes
maxEntrypointSize: number, // Total size (of an entry point) limit in bytes
hints: string // "warning" or "error"
}
Sets resolve.alias. Use it to manually override module resolving.
Example usage: resolveAliases({ foo: path.resolve('./bar.js') })
will make require('foo')
resolve to bar.js
.
Sets the webpack context. Not to be confused with the webpack-block's context
object.
Use it to manually set the webpack devtool property, like 'eval'
, 'source-map'
and such.
Sets the webpack output property. Use it to tell webpack where to save the output bundle(s).
You can either pass an object that complies to the format described in the webpack docs or just pass the destination file path.
Instead of passing the destination file path you can also
./build/
./
): The filename will default to bundle.js
.Just a convenience wrapper to enable sourcemaps in an easier-to-read fashion than setDevTool()
. Will set webpack's devtool
to 'cheap-module-source-map'
if no explicit devtool
is passed as parameter.
Check out the
Released under the terms of the MIT license.