bem / bem-xjst

bem-xjst (eXtensible JavaScript Templates): declarative template engine for the browser and server
https://bem.github.io/bem-xjst
Other
116 stars 48 forks source link

Use bem-xjst with browserify #249

Closed zefirka closed 8 years ago

zefirka commented 8 years ago

I have some requires of CommonJS modules in my bemhtml templates. Like a:

// a.bemhtml.js
block('a').match(
    // some code
    var myModule = require('moduleName');
    //some code
  )

I'm building my templates with enb-bemxjst and at the end I will get ?.bemhtml.js bundle. There are requires from bem-xjst in code:

//some code:
var inherits = require('inherits');
var Match = require('../bemxjst/match').Match;
var BemxjstEntity = require('../bemxjst/entity').Entity;

Also I have requires from my templates in this bundle. But when I try to resolve requires in my bemhtml templates with browserify - I can't do it cause of browserify can't resolve requires from bem-xjst code. Has anybody solved this problem?

Currently, in my enb technology I'm parsing bundle file, replacing all bem-xjst requirements with some strings, after I build an next bundle and replace in final bundle that strings with initial bem-xjst requires. It's pretty weird and absolutely non-maintainable solution, but currently it works.

tadatuta commented 8 years ago

@zefirka you may use https://github.com/enb/enb-bemxjst#%D0%9F%D0%BE%D0%B4%D0%BA%D0%BB%D1%8E%D1%87%D0%B5%D0%BD%D0%B8%D0%B5-%D1%81%D1%82%D0%BE%D1%80%D0%BE%D0%BD%D0%BD%D0%B8%D1%85-%D0%B1%D0%B8%D0%B1%D0%BB%D0%B8%D0%BE%D1%82%D0%B5%D0%BA

miripiruni commented 8 years ago

@zefirka the question is closed?

zefirka commented 8 years ago

@miripiruni Pretty much. Thanks! It work. But when I use module names like:

requires: {
    'module-name': { ... }
}

In final bundle in object which describes requirements I have:

{
    module-name: require('<path to module>')
}
qfox commented 8 years ago

@zefirka Thank you. Closing this since it's a bug in enb-bemxjst module: https://github.com/enb/enb-bemxjst/issues/170