Issue 1:
I have been trying to figure this out for over an hour now. Here is the subject code:

const ENVIRONMENT = process.env.NODE_ENV;
const BASENAME = process.env.APP_BASENAME;

console.log('process.env', {
ENVIRONMENT: ENVIRONMENT,
'process.env': process.env,
NODE_ENV: process.env.NODE_ENV,
APP_BASENAME: process.env.APP_BASENAME
});

if (ENVIRONMENT !== 'development' && ENVIRONMENT !== 'production') {
throw new Error('Unknown ENVIRONMENT.');
}

export {
BASENAME,
ENVIRONMENT
};

Here is my webpack config:

const webpack = require('webpack');
const path = require('path');

module.exports = {
devtool: 'source-map',
debug: false,
context: __dirname,
entry: {
'app': [
path.resolve(__dirname, './src/app')
]
},
output: {
path: path.resolve(__dirname, './dist'),
filename: '[name].js',
publicPath: '/static/'
},
plugins: [
new webpack.optimize.UglifyJsPlugin({
compressor: {
/* eslint-disable camelcase */
screw_ie8: true,
/* eslint-enable */
warnings: false
}
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"production"',
'process.env.APP_BASENAME': '"' + (process.env.APP_BASENAME || '') + '"'
}),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"',
APP_BASENAME: '"' + (process.env.APP_BASENAME || '') + '"'
}
}),
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.optimize.DedupePlugin(),
new webpack.NoErrorsPlugin()
],
module: {
loaders: [
{
include: path.resolve(__dirname, './src'),
loader: 'babel',
test: /\.js$/,
},
{
loaders: [
'style?sourceMap',
'css?modules&importLoaders=1&localIdentName=[name]___[local]___[hash:base64:5]',
'resolve-url',
'sass?sourceMap'
],
test: /\.scss$/
}
]
}
};

As you can see, I have tried multiple methods of using DefinePlugin:

new webpack.DefinePlugin({
'process.env.NODE_ENV': '"production"',
'process.env.APP_BASENAME': '"' + (process.env.APP_BASENAME || '') + '"'
}),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"',
APP_BASENAME: '"' + (process.env.APP_BASENAME || '') + '"'
}
}),

Here is the console output:

{
APP_BASENAME: "/campaign-master/upload-static",
ENVIRONMENT: undefined,
NODE_ENV: undefined,
process.env: {
APP_BASENAME: "/campaign-master/upload-static",
NODE_ENV: "production"
}
}

The script execution ends with an exception:

Uncaught Error: Unknown ENVIRONMENT.

As a result of the condition that you can see in the config.js.

What is the reason process.env.NODE_ENV is not getting replaced?

Issue 2:
Feature request

What is the expected behavior?

Various parts of Webpack's (semi-)internal runtime depend on a native Promise being available.

Currently, browsers which do not have a native implementation require that it be polyfilled globally.

It would be nice if Webpack would provide a way to hook in a local polyfill instead; one which does not require writing to window.

What is motivation or use case for adding/changing the behavior?

Projects that act as third-parties inside the websites of others generally need to minimize the way in which they affect the global environment. Currently it is impossible to avoid injecting a global polyfill for Promise when you really on key functionalities like ES6 dynamic import().

How should this be implemented in your opinion?

Centralize creation of Promise instances by code generators. (Seems a lot of it is already being done through RuntimeTemplate's blockPromise, actually.)

Add a configuration property that can be set to a user-space module to be pulled in, instead of accessing the global Promise.

Are you willing to work on this yourself?

Willing; yes. Able; no.

Simply don't have the time.