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

html-webpack-deploy-assets-plugin

v1.0.4

Published

Add the ability to deploy assets from node_modules packages

Downloads

5

Readme

Deploy Assets extension for the HTML Webpack Plugin

Enhances html-webpack-plugin functionality by allowing you to specify js or css assets from node_modules to be copied and included.

Installation

You must be running webpack on node 0.12.x or higher

Install the plugin with npm:

$ npm install --save-dev html-webpack-deploy-assets-plugin

Options

The available options are:

  • packagePath: string

    The path to installed packages, relative to the current directory. Default is node_modules.

  • append: boolean

    Specifies whether the assets will be appended (true) or prepended (false) to the list of assets in the html file. Default is false.

  • publicPath: boolean or string

    Specifying whether the assets should be prepended with webpack's public path or a custom publicPath (string).

    A value of false may be used to disable prefixing with webpack's publicPath, or a value like myPublicPath/ may be used to prefix all assets with the given string. Default is true.

  • outputPath: string

    A directory name that will be created for each of the deployed assets.

    Instances of [name] will be replaced with the package name. Instances of [version] will be replaced with the package version.

    Default is [name]-[version].

  • packages: object

    Specifies the definition of the assets from installed packages to be deployed. Defaults is {}.

    The keys/properties of the packages option must be the name of an installed package, and the definition must be an object with the following properties:

    • 'outputPath': string

    Allows the global outputPath to be overriden on a per-package basis. Default is the global value.

    • assets: object

    Specifies files or directories to be copied from the package's directory.

    The keys/properies are the asset to be copied, and the values are the target asset location within webpack's output directory.

    These are used as the from & to properties for the internal usage of the copy-webpack-plugin

    • entries: array

    Specifies files to be included in the html file.

    The file paths should be relative to webpack's output directory.

  • assets: object

    Specifies the definition of the local assets to be deployed. Defaults is {}.

    The keys/properies are the asset to be copied, and the values are the target asset location within webpack's output directory.

  • links: array

    Specifies the definition of the links to be deployed. Defaults is [].

    The objects in the links are of the shape:

    {
      href: "path/to/asset", // required - must be a string
      rel: "icon",           // required - must be a string
      sizes: '16x16',            // example of optional extra attribute
      anyOtherAttribute: 'value'
    }

    For which the following would be injected into the html header:

    <head>
      <link href="${webpack.publicPath}/path/to/asset" rel="icon" sizes="16x16" anyOtherAttribute="value"/>
    </head>

Example

Deploying bootstrap css and fonts and an assets directory from local files:

plugins: [
  new HtmlWebpackPlugin(),
  new HtmlWebpackDeployAssetsPlugin({
    "packages": {
      "bootstrap": {
        "assets": {
          "dist/css": "css/",
          "dist/fonts": "fonts/"
        },
        "entries": [
          "css/bootstrap.min.css",
          "css/bootstrap-theme.min.css"
        ]
      }
    },
    "assets": {
      "src/assets": "assets/"
    }
    "link": [
      {
        "href": "/assets/icon.png",
        "rel": "icon"
      }
    ]
  })
]

This will generate a dist/index.html with your webpack bundled output and the following:

<!DOCTYPE html>
<html>
 <head>
   <meta charset="UTF-8">
   <title>Webpack App</title>
   <link href="bootstrap-3.3.7/css/bootstrap.min.css" rel="stylesheet">
   <link href="bootstrap-3.3.7/css/bootstrap-theme.min.css" rel="stylesheet">
   <link href="bootstrap-3.3.7/css/bootstrap-theme.min.css" rel="stylesheet">
   <link href="/assets/icon.png" rel="icon">
 </head>
 <body>
   <script src="index_bundle.js"></script>
 </body>
</html>

Note that additionally, the contents of the following directories will be copied:

node_modules/bootstrap/dist/css -> dist/bootstrap-3.3.7/css node_modules/bootstrap/dist/fonts -> dist/bootstrap-3.3.7/fonts src/assets -> dist/assets