Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including metalsmith-webpack-2 with all npm packages installed. Try it out:

var metalsmithWebpack2 = require("metalsmith-webpack-2")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

metalsmith-webpack-2 v1.0.5

A webpack plugin for Metalsmith

metalsmith-webpack-2

nodei.co

npm github-issues stars forks

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.

See Also

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free