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-dynamic-env-plugin

v0.0.2

Published

Extension plugin for html-webpack-plugin that allows specifying dynamic environment for static html apps

Downloads

7

Readme

Build Status

HTML Webpack Dynamic Env Plugin

This is an extension plugin for the webpack plugin html-webpack-plugin that allows configure environment variables for static html app after build step and before deployment (e.g. push to cdn or docker run)

How does it work?

This plugin subscribes on html-webpack-plugin hooks and webpack hooks, enhances output html files with default environment variables, plus generates template files for every output html with a script file to replace environment variables.

Why do I need it?

If you need/want to be able to configure your environment variables after app bundle and you don't want/can't setup heavy server side.

Installation

npm i -D html-webpack-dynamic-env-plugin

Basic Usage

Require the plugin in your webpack config:

var HtmlWebpackDynamicEnvPlugin = require('html-webpack-dynamic-env-plugin');

Add the plugin to your webpack config (remember to add it after html-webpack-plugin):

plugins: [
  new HtmlWebpackPlugin(),
  new HtmlWebpackDynamicEnvPlugin({
    envVars: {
      YOUR_ENV_VARIABLE: "default-value-here",
      ANOTHER_ENV_VAR: process.env.SET_DEFAULT_VALUE_FROM_BUILD_ENV || ''
    }
  })
]  

This will generate index.html file from HtmlWebpackPlugin with injected script tag that defines your environment defaults. It should look something like this:

window.CLIENT_ENV = { YOUR_ENV_VARIABLE: "default-value-here", ANOTHER_ENV_VAR: "" }

Plus you'll have your config-env.sh and index.html.template files generated that you can use to configure your environment again, like this:

YOUR_ENV_VARIABLE=newvalue ./config-env.sh index.html.template index.html

Configuration

List of available configuration options:

|Name|Type|Default|Description| |:--:|:----:|:--:|:----------| |envVars|{ [key: string]: string \| undefined }|``|Key-value map of environment variables. Values will be used as defaults in generated html output file| |windowKeyName|string|'CLIENT_ENV'|Property name to be used on window object to store environment variables| |injectEnvVars|(string, string, string) => string|headAppend|Function that injects environment variables into html and template files. takes html, script tag with env and filename as parameters, returns html with injected tag. By default appeands to head tag| |configFileName|string|'config-env.sh'|File name for the generated configuration script| |configFactoryFunc|string \| envs => string|'shell'|Configuration script factory function. Can be either pre-defined type, e.g. 'shell' or a custom function-factory of the type: takes envVars type in and returns script file content as a string| |templateFileNames|{ [key: string]: string }|{}|Key-value map, where: key - file name of generated by html-webpack-plugin html file; value - template file name for this html.For every not specified html filename - template with default pattern-name will be generated. I.e. { "index.html": "index.html.template" }|

Examples

You can find examples in Examples folder.