define-env-plugin

Enable client code to get node variables

Usage no npm install needed!

<script type="module">
  import defineEnvPlugin from 'https://cdn.skypack.dev/define-env-plugin';
</script>

README

define-env-plugin

Enable client code to get node variables

Installation

yarn add define-env-plugin -D

Usage

// webpack.config.js

const DefineEnvPlugin = require('define-env-plugin');

module.exports = {
  plugins: [
    // 
    new DefineEnvPlugin(['APP_VERSION', 'AUTHOR'])
  ]
};

In client code use it

// main.js
// process.env can get the fields in the scripts of package.js

console.log(process.env);

Options

NODE_ENV and SERVICE_URL are built in by default, You can pass in other fields

  DefineEnvPlugin(['APP_VERSION', 'AUTHOR'])

Available options are:

NODE_ENV (string): environment for browser.

SERVICE_URL (string): http url for api.

SOCKET_URL (string): websocket url for api.