-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
34 lines (28 loc) · 863 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
var path = require("path");
var loaderUtils = require("loader-utils");
var fs = require('fs');
var vm = require('vm');
module.exports = function(content) {
var environment;
try {
environment = this.options.loader.configEnvironment || 'development';
}
catch (e) {
environment = 'development';
console.error('Missing loader.configEnvironment key from webpack config. Assuming "development".');
}
/*
Run code in a special context
*/
var sandbox = { module: {} };
vm.runInNewContext(content, sandbox, this.resourcePath);
/*
Grab the appropriate configuration based on environment
*/
var allConfigs = sandbox.module.exports
var envConfig = allConfigs[environment] || {};
if (!envConfig.environment) {
envConfig.environment = environment;
}
return "module.exports = " + JSON.stringify(envConfig) + ";"
};