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

https://github.com/leegeunhyeok/inject-assets-list-webpack-plugin

Inject webpack assets list into your HTML template
https://github.com/leegeunhyeok/inject-assets-list-webpack-plugin

assets webpack webpack-plugin

Last synced: 3 months ago
JSON representation

Inject webpack assets list into your HTML template

Awesome Lists containing this project

README

          

[![npm][npm]][npm-url]
[![node][node]][node-url]
![npm](https://img.shields.io/npm/dw/inject-assets-list-webpack-plugin.svg)





Inject Assets List Webpack Plugin


Inject assets list into your HTML template


## Install

- This Plugin dependent on [HtmlWebpackPlugin](https://github.com/jantimon/html-webpack-plugin)

```bash
npm i --save-dev inject-assets-list-webpack-plugin
```

```bash
yarn add --dev inject-assets-list-webpack-plugin
```

## Usage

The plugin will generate an JS array for you that includes all your `webpack`
assets(RawSource) in the `` using `` tags. Just add the plugin to your `webpack`
config as follows:

**webpack.config.js**

```js
// !! HtmlWebpackPlugin required
const HtmlWebpackPlugin = require('html-webpack-plugin');
const InjectAssetsListWebpackPlugin = require('inject-assets-list-webpack-plugin');

module.exports = {
entry: 'index.js',
publicPath: '/',
output: {
path: __dirname + '/dist',
filename: 'bundle.js',
},
plugins: [new HtmlWebpackPlugin(), new InjectAssetsListWebpackPlugin()],
};
```

This will generate a file `dist/index.html` containing the following

```html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Webpack App</title>
<script type="text/javascript">
var __assets = [
'/img/apple.707709ec.png',
'/img/banana.51a48343.png',
/* Webpack assets */
];