Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

metalsmith-webpack-2

1.0.5 • Public • Published

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

install

npm i metalsmith-webpack-2

Downloadsweekly downloads

2

version

1.0.5

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability