-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathindex.js
86 lines (71 loc) · 2.37 KB
/
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
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
// Support old versions of Ember CLI.
function findHost() {
var current = this;
var app;
// Keep iterating upward until we don't have a grandparent.
// Has to do this grandparent check because at some point we hit the project.
// Stop at lazy engine boundaries.
do {
if (current.lazyLoading === true) { return current; }
app = current.app || app;
} while (current.parent && current.parent.parent && (current = current.parent));
return app;
}
module.exports = {
name: 'ember-browserify',
included: function(app){
var VersionChecker = require('ember-cli-version-checker');
var checker = new VersionChecker(this);
var emberCliVersion = checker.for('ember-cli', 'npm');
var newImportApi;
if (emberCliVersion.isAbove('1.13.8')) {
newImportApi = true;
}
app = findHost.call(this);
var enableSourcemaps = app.options.sourcemaps && app.options.sourcemaps.enabled && app.options.sourcemaps.extensions.indexOf('js') > -1;
this.app = app;
this.options = {
root: this.app.project.root,
browserifyOptions: app.project.config(app.env).browserify || {},
enableSourcemap: enableSourcemaps,
fullPaths: app.env !== 'production'
};
app.import('browserify/browserify.js');
if (app.tests && (process.env.BROWSERIFY_TESTS || this.options.browserifyOptions.tests)) {
if (newImportApi) {
app.import('browserify-tests/browserify.js', {
type: 'test'
});
} else {
app.import({
test: 'browserify-tests/browserify.js'
});
}
}
if (app.importWhitelistFilters) {
app.importWhitelistFilters.push(function(moduleName){
return moduleName.slice(0,4) === 'npm:';
});
}
},
postprocessTree: function(type, tree){
var outputFile, options;
if (type === 'js'){
outputFile = 'browserify/browserify.js';
} else if (type === 'test'){
outputFile = 'browserify-tests/browserify.js';
}
if (outputFile) {
var StubGenerator = require('./stub-generator');
var CachingBrowserify = require('./caching-browserify');
var MergeTrees = require('broccoli-merge-trees');
options = Object.create(this.options);
options.outputFile = outputFile;
tree = new MergeTrees([
tree,
new CachingBrowserify(new StubGenerator(tree), options)
]);
}
return tree;
}
};