An open API service indexing awesome lists of open source software.

https://github.com/kaelzhang/assets-html-webpack-plugin

Handle JavaScript or CSS assets to the HTML, woking with html-webpack-plugin
https://github.com/kaelzhang/assets-html-webpack-plugin

assets hash webpack webpack-plugin

Last synced: 2 months ago
JSON representation

Handle JavaScript or CSS assets to the HTML, woking with html-webpack-plugin

Awesome Lists containing this project

README

          

[![Build Status](https://travis-ci.org/kaelzhang/assets-html-webpack-plugin.svg?branch=master)](https://travis-ci.org/kaelzhang/assets-html-webpack-plugin)

# assets-html-webpack-plugin

Handle JavaScript or CSS assets to the HTML, woking with [html-webpack-plugin](https://www.npmjs.com/package/html-webpack-plugin)

- Supports to add vendors to html pages.
- Fallback to global output configuration of webpack.

## Install

```sh
$ npm install assets-html-webpack-plugin --save-dev
```

## Usage

```js
// html-webpack-plugin@^2.10.0 is required
const HtmlPlugin = require('html-webpack-plugin')
const AssetsPlugin = require('assets-html-webpack-plugin')
const webpackConfig = {
output: {
path: '/path/to',
...
},
plugins: [
new HtmlPlugin(...),
new AssetsPlugin({
// Suppose the filepath is '/src/foo.js'
assets: [require.resolve('./path/to/foo')],
chunks: ['vendor'],
output: {
filename: 's/[name].[chunkhash].js',
publicPath: '//mycdn.com/m'
}
})
]
}
```

Then, `/src/foo.js` will be copied to

```
/path/to/s/
|-- foo.26313ef12faa88b00420.js
```

And the following script tags will be injected into the html:

```html

```

Notice that `assets` scripts will come first, then `chunks`.

## new AssetsPlugin(options [, options, ...])

**options** `Object`

- **assets** `Array.`
- **chunks** `Array.`

If both `assets` and `chunks` are empty or not defined, an error will throw.

- **output.filename** `String` default to `webpack.config.output.filename`. Which will not affect `chunks`.
- **output.publicPath** `String` default to `webpack.config.output.publicPath`
- **append** `Boolean=false` whether the assets will be append to the end of the existing assets
- **typeOfAsset** `String.=` Optional. Specify the type of the asset. By default, `AssetPlugin` will detect the extname of the filepath.

## License

MIT