Socket
Book a DemoInstallSign in
Socket

node-env-webpack-plugin

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-env-webpack-plugin

Simplified `NODE_ENV` handling with webpack

latest
Source
npmnpm
Version
2.0.0
Version published
Maintainers
1
Created
Source

node-env-webpack-plugin

Simplified NODE_ENV handling with webpack

Install

npm install node-env-webpack-plugin

Usage

  import path from 'node:path';
+ import NodeEnvPlugin from 'node-env-webpack-plugin';

- const NODE_ENV = process.env.NODE_ENV || 'development';
- const isProduction = NODE_ENV === 'production';

  module.exports = {
  	entry: './source',
  	output: {
  		path: path.join(__dirname, 'distribution'),
  		filename: 'bundle.js'
  	},
- 	devtool: isProduction ? 'source-map' : 'cheap-module-source-map',
+ 	devtool: NodeEnvPlugin.devtool,
  	module: {
  		rules: [
  			{
  				test: /\.js$/,
  				exclude: /node_modules/,
  				loader: 'babel-loader'
  			}
  		]
  	},
  	plugins: [
- 		new webpack.EnvironmentPlugin({
- 			NODE_ENV: 'development'
- 		}),
+ 		new NodeEnvPlugin()
  	]
  };

API

Sets process.env.NODE_ENV in the Node.js process to development at import-time if it's not defined, or production if webpack is run with webpack -p.

NodeEnvPlugin()

Sets process.env.NODE_ENV in the bundle to the same as in the Node.js process.

NodeEnvPlugin.isProduction

For convenience and to prevent typos.

process.env.NODE_ENV === 'production'

NodeEnvPlugin.isDevelopment

process.env.NODE_ENV === 'development'

NodeEnvPlugin.isTest

process.env.NODE_ENV === 'test'

NodeEnvPlugin.devtool

Pass this to the webpack devtool option. It will give you good but slow source maps in production (source-map) and fast source maps in development (cheap-module-source-map).

  • add-asset-webpack-plugin - Dynamically add an asset to the webpack graph

Keywords

webpack-plugin

FAQs

Package last updated on 30 Apr 2024

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