metalsmith-webpack-2
A webpack plugin for Metalsmith.
See the annotated source or github repo.
Installation
npm install metalsmith-webpack-2
Usage
import webpack from 'metalsmith-webpack-2'
Metalsmith(__dirname)
.use(webpack(options))
.build()
Options
options
may be:
- a webpack configuration object.
- a path to your webpack configuration file
- null / undefined, config will be read from
webpack.config.js
Example
Construct your webpack config exactly as you would if you were calling webpack from the command line.
Metalsmith(__dirname)
.use(webpack({
entry: {
site: resolve(__dirname, 'src', 'js', 'site.js'),
},
output: {
path: resolve(__dirname, 'build', 'js'),
filename: '[name].[chunkhash].js'
}
}))
.build()
Note: It's important that absolute paths are provided to webpack, as is normal webpack behaviour. That means including your src
and build
directories as demonstrated above.
This example uses an asset's hash in it's filename (fingerprinting / cache busting). The filename for this asset will be stored in metalsmith meta, so you could access it from a template with something like:
<script src="{{webpack.assets['site']}}"></script>
This plugin will not ignore source files, you should use metalsmith-ignore for that
See the tests for more examples, or metalsmith-all-the-things for a full implementation.
Tests
$ npm test
License
MIT License, see LICENSE for details.