<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Trim Agency &#187; webpack</title>
	<atom:link href="http://old.trimagency.com/tag/webpack/feed/" rel="self" type="application/rss+xml" />
	<link>http://old.trimagency.com</link>
	<description></description>
	<lastBuildDate>Mon, 29 Jun 2026 06:32:54 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.42</generator>
	<item>
		<title>Environment Variables in Webpack</title>
		<link>http://old.trimagency.com/environment-variables-in-webpack/</link>
		<comments>http://old.trimagency.com/environment-variables-in-webpack/#comments</comments>
		<pubDate>Sun, 29 Jan 2017 20:23:07 +0000</pubDate>
		<dc:creator><![CDATA[Dom Miller]]></dc:creator>
				<category><![CDATA[Team Trim]]></category>
		<category><![CDATA[Today I Learned]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[webpack]]></category>

		<guid isPermaLink="false">http://trimagency.com/?p=2492</guid>
		<description><![CDATA[<p>Diving into webpack module loader can often seem like a confusing and daunting task. Luckily, setting environment variables is rather straight forward. At the top of your webpack.config.js file define your environment variables like so: Then in the plugins array use DefinePlugin method to define global variables configured at compile time: Re-compile and now your [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://old.trimagency.com/environment-variables-in-webpack/">Environment Variables in Webpack</a> appeared first on <a rel="nofollow" href="http://old.trimagency.com">Trim Agency</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Diving into webpack module loader can often seem like a confusing and daunting task.<br />
Luckily, setting environment variables is rather straight forward.</p>
<p>At the top of your webpack.config.js file define your environment variables like so:</p>
<pre class="brush: jscript; title: ; notranslate">
/**
 * Example Constants
 */
const ENV = process.env.ENV = process.env.NODE_ENV = 'development';
const API_URL = process.env.API_URL = 'http://localhost:3000';
const METADATA = {
  API_URL: API_URL,
  ENV: ENV
};
</pre>
<p>Then in the plugins array use DefinePlugin method to define global variables configured at compile time:</p>
<pre class="brush: jscript; title: ; notranslate">
/**
 * Make Webpack Constants Available Globally
 */
   new webpack.DefinePlugin({
     'ENV': JSON.stringify(METADATA.ENV),
     'API_URL': JSON.stringify(METADATA.API_URL),
     'process.env': {
       'ENV': JSON.stringify(METADATA.ENV),
       'NODE_ENV': JSON.stringify(METADATA.ENV),
       'API_URL' : JSON.stringify(METADATA.API_URL),
     }
   }),
</pre>
<p>Re-compile and now your variables will be globally available.</p>
<p>The post <a rel="nofollow" href="http://old.trimagency.com/environment-variables-in-webpack/">Environment Variables in Webpack</a> appeared first on <a rel="nofollow" href="http://old.trimagency.com">Trim Agency</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://old.trimagency.com/environment-variables-in-webpack/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
