-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.js
57 lines (46 loc) · 1.29 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
/* eslint-env node */
'use strict';
const hashObj = require('hash-obj');
module.exports = {
name: 'ember-hbs-minifier',
_setupPreprocessorRegistry(app) {
let registry = app.registry;
let options = app.options || {};
let config = options['ember-hbs-minifier'] || {};
let pluginObj = this._buildPlugin(config);
pluginObj.parallelBabel = {
requireFile: __filename,
buildUsing: '_buildPlugin',
params: config,
};
registry.add('htmlbars-ast-plugin', pluginObj);
},
included(app) {
this._super.included.apply(this, arguments);
/*
Calling setupPreprocessorRegistry in included hook since app.options is not accessible
Refer PR: https://github.com/ember-cli/ember-cli/pull/7059
*/
this._setupPreprocessorRegistry(app);
},
_buildPlugin(config) {
let HbsMinifierPlugin = require('./hbs-minifier-plugin').createRegistryPlugin(config);
return {
name: 'hbs-minifier-plugin',
plugin: HbsMinifierPlugin,
baseDir() {
return __dirname;
},
cacheKey() {
return cacheKeyForConfig(config);
},
};
},
};
function cacheKeyForConfig(config) {
let configHash = hashObj(config, {
encoding: 'base64',
algorithm: 'md5',
});
return `ember-hbs-minifier-${configHash}`;
}