Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

htmls-webpack-plugin

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

htmls-webpack-plugin

A simple, fast, flexible and multiple html webpack plugin.

  • 2.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

htmls-webpack-plugin

Build Status npm npm

Simple, flexible and fast html webpack plugin.

NOTE: v2 support webpack5, if you still using webpack4, please install htmls-webpack-plugin@v1.0.9

Features

  • Simple and flexisble, you can almost controll anything of generate htmls, no need of setup lots of plugins.
  • Support multiple htmls by default
  • Fast, almost 20x faster then html-webpack-plugin for 20+ pages.

Install

npm i -D htmls-webpack-plugin

Usage

const HtmlsWebpackPlugin = require('htmls-webpack-plugin')

module.exports = {
    plugins: [
        new HtmlsWebpackPlugin({
             // optional, hooks
            beforeEmit: (compilation, compiler) => void,
             // optional, hooks
            afterEmit: (compilation, compiler) => void,
             // optional, default is ejs. custom template rendering function, support async rendering,
            render: (file, params) => string | Promise<string>,
            htmls: [{
                // template path
                src: '',
                // string | ((source, src, params) => string), relative to output path, can be a function to be generated via context
                filename: '',
                // optional, override global render function
                render: (file, params) => string | Promise<string>,
                // optional, override global flushOnDev
                flushOnDev: boolean | string
                // custom params when rendering
                params: () => object | () => Promise<object> | object
                // transformParams, override global transformParams
                transformParams?: (params: Params) => Params & { [k: string]: any }
            }],

             /* boolean | string, flush html files to dist, can be a string file path, useful for debug or devServer. */
            flushOnDev: false,

             /* optional, override webpackConf's publicPath */
            publicPath: function | string',

            // optional, custom params when rendering, could be an async function
            params: () => object | () => Promise<object> | object

            // transformParams
            transformParams?: (params: Params) => Params & { [k: string]: any }
        })
    ]
}

The variables in html templates:

interface Params {
  entries: string[] // all entrypoints
  files: string[] // all files
  jses: string[] // all files ends with .js
  csses: string[] // all files ends with .css
  options: Props // plugin props
  compilation: Compilation // webpack compilation
  [k: string]: any // custom params via options
}

ejs example

<body>
    <% for (let js in entries) {%>
        <script src="<%= js %>"></script>
    <% } %>
</body>

Why not html-webpack-plugin

html-webpack-plugin is really hard to extends and slow for multiple htmls, too much complete features that I don't need. That's why I create this.

License

MIT

FAQs

Package last updated on 19 Apr 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc