V
V
Vladimir Gorbunov2016-03-17 21:18:40
JavaScript
Vladimir Gorbunov, 2016-03-17 21:18:40

Is there any way to universally add files?

There is a plugin

new HandlebarsPlugin({
            // path to main hbs template
            entry: path.join(process.cwd(), "app", "src", "index.hbs"),
            // filepath to result
            output: path.join(process.cwd(), "build", "index.html")
        })

This is how the import of a file goes, but this is the import of a specific file. And if I want to import all files from this folder, and display the same amount. Tried to put "*.hbs", did not help! Maybe someone used these plugins and knows how to solve this problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Q
qtuz, 2016-03-30
@LaBeuof

Scan a directory, get a list of files, and create as many plugin instances as there are in the folder:

var glob = require('glob');
var files = glob.sync('lib/*.js');

...

plugins: files.map(function(filepath) {
  var basename = path.basename(filepath);
  var basenameWithoutExtension = basename.substr(0, basename.lastIndexOf("."));
  return new HandlebarsPlugin({
    entry: path.resolve(process.cwd(), filepath),
    output: path.join(process.cwd(), 'build', basenameWithoutExtension + '.html')
  });
});

H
hydra_13, 2016-03-17
@hydra_13

See if the doc for this plugin can help:
https://github.com/wycats/handlebars.js/blob/maste...
or
handlebarsjs.com

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question