forked from vellama/webpack-env-loader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (33 loc) · 781 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
35
36
37
38
39
40
41
42
43
44
'use strict';
var loaderUtils = require('loader-utils');
var vm = require('vm');
module.exports = function (content) {
var app;
var env;
var md;
var sandbox = { module: {} };
var settings;
this.cacheable();
vm.runInNewContext(content, sandbox, this.resourcePath);
md = sandbox.module.exports;
try {
app = this.options.loader.appSettings.name || 'app';
} catch (e) {
app = 'app';
}
try {
env = this.options.loader.appSettings.env || 'development';
} catch (e) {
env = 'development';
}
if (md[app] && !md[app][env]) {
settings = md[app];
}
if (md[app] && md[app][env]) {
settings = md[app][env];
}
if (md[env]) {
settings = md[env];
}
return 'module.exports = ' + JSON.stringify(settings) + ';';
};