webpack val loader causing exceptions
<p>I'm trying to dynamically include a .js file at webpack compile time.  </p>

<p>I don't want to use a context to load environmental variables, because I don't these magic variables in my code. </p>

<p>What I'm trying to do is use the val loader to execute a module.  There use an environment variable to decide what module to import. And export that module.</p>

<p>However, this is causing other loaders to throw errors.  </p>

<p>Here's my dir layout</p>

<pre><code>--base
  --src
    app.js
    test.js
  webpack.config.js
  rawr.js
</code></pre>

<p>Here my webpack.config.js file</p>

<pre><code>var path = require('path');
var webpack = require('webpack');
// var process = require('process');

var env = require(process.env.NODE_ENV || './devConf.js');

module.exports = {
    // Specify logical root of the sourcecode
    plugins: [
        new webpack.DefinePlugin(env)
    ],
    context: path.join(__dirname, '/src'),
    entry: {
    app: ['bootstrap.js'],
  },

    // Specify where to put the results
    output: {
        path: path.join(__dirname, '/dist'),
        filename: 'build.js'
    },

    // Specify logical root of package imports so as to avoid relative path everywhere
    resolve: {
        root: path.join(__dirname, '/src'),
        // What files we want to be able to import
        extensions: ['', '.js', '.css', '.less'],
    },

    module: {
        preLoaders: [
            // Lint all js before compiling
            /*{
                test: /\.js$/,
                exclude: /node_modules/,
                loader: 'eslint-loader'
            }*/
        ],
        loaders: [
            {
                test: /\.js$/,
                query: {
                    presets: ['es2015']
                },
                exclude: /node_modules/,
                loader: 'babel'
            },
            {
                test: /\.tpl\.html$/,
                exclude: /node_modules/,
                loader: 'ngtemplate?relativeTo=/src/!html'
            },
      {
        test: /\.scss$/,
        loaders: ["style", "css", "sass"]
      },
      {
        test: /\.css$/,
        loaders: ["style", "css"]
      }
        ]
    },

    // Dev server settings
    devServer: {
        contentBase: path.join(__dirname, '/dist'),
        noInfo: false,
        hot: true
    },

    // ESLint config
    eslint: {
        configFile: path.join(__dirname, '.eslintrc')
    }
};
</code></pre>

<p>My js files look like this</p>

<pre><code>// app.js
let b = require('val!test.js');

// test.js
var process = require('process');
loadedModule = require(process.env.NODE_ENV) // NODE_ENV='./rawr.js'
export const myString = loadedModule

// rawr.js
module.exports.test = "hello world";
</code></pre>

<p>The exception I'm getting:</p>

<pre><code>ERROR in ./src/app/app.js
Module parse failed: /home/smaug/Projects/angular-template/node_modules/babel-loader/index.js?{"presets":["es2015"]}!/home/smaug/Projects/angular-template/src/app/app.js Line 1: Unexpected identifier
You may need an appropriate loader to handle this file type.
| 'use strict';
| 
| require('angular-animate');
 @ ./src/bootstrap.js 7:0-18
</code></pre>

<p>It has nothing to do with what I'm trying to do. But if I remove the require('val!...') statment, it goes away.</p>

<p>Any ideas?</p>

<p>UPDATE:</p>

<p>If I change the require statement to be</p>

<pre><code>let b = require('val!./test.js');
</code></pre>

<p>I get the following error: </p>

<pre><code>ERROR in ./~/val-loader!./src/app/test.js
Module build failed: Error: Final loader didn't return a Buffer or String
    at DependenciesBlock.onModuleBuild (/home/smaug/Projects/angular-template/node_modules/webpack-core/lib/NormalModuleMixin.js:299:42)
    at nextLoader (/home/smaug/Projects/angular-template/node_modules/webpack-core/lib/NormalModuleMixin.js:275:25)
    at /home/smaug/Projects/angular-template/node_modules/webpack-core/lib/NormalModuleMixin.js:292:15
    at runSyncOrAsync (/home/smaug/Projects/angular-template/node_modules/webpack-core/lib/NormalModuleMixin.js:160:12)
    at nextLoader (/home/smaug/Projects/angular-template/node_modules/webpack-core/lib/NormalModuleMixin.js:290:3)
    at /home/smaug/Projects/angular-template/node_modules/webpack-core/lib/NormalModuleMixin.js:292:15
    at Object.context.callback (/home/smaug/Projects/angular-template/node_modules/webpack-core/lib/NormalModuleMixin.js:148:14)
    at Object.module.exports (/home/
</code></pre>