-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathes6.js
106 lines (96 loc) · 3.59 KB
/
es6.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
define([
//>>excludeStart('excludeBabel', pragmas.excludeBabel)
'babel', 'babel-plugin-module-resolver',
'module'
//>>excludeEnd('excludeBabel')
], function(
//>>excludeStart('excludeBabel', pragmas.excludeBabel)
babel, moduleResolver,
_module
//>>excludeEnd('excludeBabel')
) {
//>>excludeStart('excludeBabel', pragmas.excludeBabel)
var fetchText, _buildMap = {};
if (typeof window !== 'undefined' && window.navigator && window.document) {
fetchText = function (url, callback) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.onreadystatechange = function (evt) {
//Do not explicitly handle errors, those should be
//visible via console output in the browser.
if (xhr.readyState === 4) {
callback(xhr.responseText);
}
};
xhr.send(null);
};
} else if (typeof process !== 'undefined' &&
process.versions &&
!!process.versions.node) {
//Using special require.nodeRequire, something added by r.js.
var fs = require.nodeRequire('fs');
fetchText = function (path, callback) {
callback(fs.readFileSync(path, 'utf8'));
};
}
babel.registerPlugin('module-resolver', moduleResolver);
function resolvePath (sourcePath) {
if (sourcePath.indexOf('!') < 0) {
return 'es6!' + sourcePath;
}
}
var excludedOptions = ['extraPlugins', 'resolveModuleSource'];
var pluginOptions = _module.config();
var fileExtension = pluginOptions.fileExtension || '.js';
var defaultOptions = {
plugins: (pluginOptions.extraPlugins || []).concat([
'transform-modules-amd',
[
'module-resolver',
{
resolvePath: pluginOptions.resolveModuleSource || resolvePath
}
]
])
};
for (var key in pluginOptions) {
if (pluginOptions.hasOwnProperty(key) && excludedOptions.indexOf(key) < 0) {
defaultOptions[key] = pluginOptions[key];
}
}
//>>excludeEnd('excludeBabel')
return {
//>>excludeStart('excludeBabel', pragmas.excludeBabel)
load: function (name, req, onload, config) {
var sourceFileName = name + fileExtension;
var url = req.toUrl(sourceFileName);
if (url.indexOf('empty:') === 0) {
return onload();
}
var options = {};
for (var key in defaultOptions) {
options[key] = defaultOptions[key];
}
options.sourceFileName = sourceFileName;
options.sourceMap = config.isBuild ? false : 'inline';
fetchText(url, function (text) {
var code;
try {
code = babel.transform(text, options).code;
} catch (error) {
return onload.error(error);
}
if (config.isBuild) {
_buildMap[name] = code;
}
onload.fromText(code);
});
},
write: function (pluginName, moduleName, write) {
if (moduleName in _buildMap) {
write.asModule(pluginName + '!' + moduleName, _buildMap[moduleName]);
}
}
//>>excludeEnd('excludeBabel')
};
});