Skip to content

leviwheatcroft/metalsmith-webpack-2

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code
This branch is 50 commits ahead of christophercliff:master.

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
lib
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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

About

A webpack plugin for Metalsmith

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%