npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

easy-html-webpack-plugin

v1.0.0

Published

a easy and flexible plugin for webpack to injecting js and css into html

Downloads

4

Readme

Easy HTML Webpack Plugin

A webpack plugin that automatically injects js and css files with their suffixes into html

npm

Features

Does not produce a different hash suffix js or css files each time after webpack compilation

But can dependen on webpack.HashedModuleIdsPlugin to keep module.id stable when vendor modules does not change

It could make your server reduce duplicate files (different hash values for the same file) and cache the third-party code(vendor.js) in browser

After webpack compilation:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <title>Document</title>
  <link rel="stylesheet" href="./static/css/app.css?fe8f1871392175ffe592" /></head>
  <body>
    <div id="app"></div>
    <!-- built files will be auto injected -->
  </body><script src="./static/js/manifest.js?8031c6b28b40ad59a31e"></script><script src="./static/js/vendor.js?bd0ae558bdc3f0975439"></script><script src="./static/js/app.js?fe8f1871392175ffe592"></script>
</html>

Installation

You must be running webpack2 or webpack3

Install the plugin with npm:


$ npm install --save-dev esay-html-webpack-plugin

Basic Usage

Require the plugin in your webpack config:

const EsayHtmlWebpackPlugin = require('esay-html-webpack-plugin')

Add the plugin to your webpack config as follows:

plugins: [
  ...
  new webpack.optimize.CommonsChunkPlugin({
    name: 'vendor',
    minChunks (module) {
      return (
        module.resource &&
        /\.js$/.test(module.resource) &&
        module.resource.indexOf(
            path.join(__dirname, '../node_modules')
        ) === 0
      )
    }
  }),
  new webpack.optimize.CommonsChunkPlugin({
    name: 'manifest',
    minChunks: Infinity
  }),
  new webpack.optimize.CommonsChunkPlugin({
    name: 'app',
    async: 'vendor-async',
    children: true,
    minChunks: 3
  }),
  // keep module.id stable when vendor modules does not change
  new webpack.HashedModuleIdsPlugin(),
  new EsayHtmlWebpackPlugin({
    inject: true,
    // filename absolute path
    filename: path.resolve(__dirname, '../dist/index.html'),
    // template absolute path
    template: path.resolve(__dirname, '../index.html'),
    // add hash to chunkFile and keep hash stable when vendor modules does not change
    hash: true,
    // Prefix of injected file
    publicPath: './',
  }),
]

When you want to change some special chunkfiles'path or want to use custom hash, you can use chunkPipe methods. For example, you can change the hash suffix of the chunkfiles to a timestamp

plugins: [
  ...
  new HtmlPlugin({
    inject: true,
    filename: path.resolve(__dirname, '../dist/index.html'),
    template: path.resolve(__dirname, '../index.html'),
    hash: true,
    publicPath: './',
    chunkPipe(chunkFile) {
      // vendor chunkFile are integrated with relatively large third-party libraries and need to be cached
      // we do not recommend customizing hash timestamps for vendor chunkFile
      if (chunkFile.indexOf('vendor') !== -1) {
        return chunkFile
      } else {
        // change the hash suffix of the chunkfile to a timestamp
        let time = new Date()
        let year = time.getFullYear()
        let month = time.getMonth() + 1
        month = month > 9 ? month : `0${month}`
        let date = time.getDate()
        date =  date > 9 ? date : `0${date}`
        return chunkFile.replace(/(\?.*)/, `?${year}${month}${date}`)
      }
    }
  }),
]

After webpack compilation:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
<link rel="stylesheet" href="./static/css/app.css?20180806" /></head>
<body>
  <div id="app"></div>
</body><script src="./static/js/manifest.js?20180806"></script><script src="./static/js/vendor.js?353bb65c911ef49e0804"></script><script src="./static/js/app.js?20180806"></script>
</html>

Demo of simple use:

simple-demo

Demo of multi-page use:

multi-page-demo

Demo used in vuel-cli2:

vue-cli-2-demo