Skip to content

Commit

Permalink
Compiler .generate(): do not require in runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
miripiruni committed Mar 15, 2017
1 parent 0d9a273 commit d6323fa
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/compiler.js
@@ -1,8 +1,13 @@
var fnToString = require('./bemxjst/utils').fnToString;
var readFileSync = require('fs').readFileSync;
var engines = {
bemhtml: require('./bemhtml'),
bemtree: require('./bemtree')
};
var bundles = {
bemhtml: readFileSync(require.resolve('./bemhtml/bundle'), 'utf8'),
bemtree: readFileSync(require.resolve('./bemtree/bundle'), 'utf8')
};

function Compiler(engineName) {
this.engineName = engineName;
Expand Down Expand Up @@ -31,11 +36,8 @@ Compiler.prototype.generate = function generate(code, options) {
'/// --------- BEM-XJST Runtime Start ----',
'/// -------------------------------------',
'var ' + exportName + ' = function(module, exports) {',
require('fs').readFileSync(
require.resolve('./' + this.engineName + '/bundle'),
'utf8'
),
';',
bundles[this.engineName],
';',
' return module.exports ||',
' exports.' + exportName + ';',
'}({}, {});',
Expand Down

0 comments on commit d6323fa

Please sign in to comment.