How do I structure modules for using hbsfy and the browser?

I would like to use browserify and hbsfy Handlebars are converted for modular JavaScript in the web application that I am writing.

Using gulp, I set up tasks to launch the browser and hbsfy to compile several js and hbs files into one, using the source structure that grouped my modules:

/src
  - /javascript
    - app.js
    - /module-one
      - module-one.js
      - module-one.hbs
    - /moduleTwo
      - module-two.js
      - module-two.hbs

However, this is due to a problem when accessing one module from another, which requires the use of fragile relative paths that need to be updated if the module is moved or even more nested.

substack wrote on Avoid .. /../../../../../ .. in his (excellent) browser. There he suggests storing application modules in a directory under node_modules.

, , , hbsfy . docs, node_modules, global true.

, :

, .

, - -? ?

+4
1

hbsfy, https://github.com/epeli/node-hbsfy/blob/master/example/index.js

, , , angularjs, https://github.com/mallim/sbangular/blob/master/src/main/resources/js/login/LoginCtrl.js

:

  app.run(['$templateCache', function($templateCache) {
    $templateCache.put('login.html', require('./login.html') );
  }]);

login.html , LoginCtrl.js

0

Source: https://habr.com/ru/post/1544071/


All Articles