How can pug files be converted to html templates without importing them explicitly to the entry point?

The project contains templates, styles, scripts for each application, which lie in a separate directory. Frontend folder:

β”œβ”€β”€ frontend β”‚  β”œβ”€β”€ common β”‚  β”œβ”€β”€ node_modules β”‚  β”œβ”€β”€ app1 β”‚  β”œβ”€β”€ app2 β”‚  β”œβ”€β”€ app3 β”‚  β”œβ”€β”€ ... β”‚  └── webpack.config.js 

Each application folder contains a different number of templates:

 β”œβ”€β”€ app β”‚  β”œβ”€β”€ static β”‚  β”‚  └── app β”‚  β”‚  β”œβ”€β”€ css β”‚  β”‚  └── js β”‚  └── templates β”‚  └── app β”‚  β”œβ”€β”€ app__tmp2.pug β”‚  β”œβ”€β”€ app.pug β”‚  β”œβ”€β”€ app__tmp1.pug β”‚  └── app__settings.pug 

Accordingly, their explicit import may be inconvenient.

The webpack documentation is written quite a bit about working with preprocessors of templates and their work requires explicit importing. I also need the collector to recursively go through all the directories and leave the converted file in place of the source code.

I tried to solve the problem myself:

  1. Used pug-loader
  2. On the advice of Moderately Uprooting the Duck from my question on Assembling individual css and scripts into common files, I decided to try glob to bypass directories and include templates as entry points (yes, it probably looks weird). Part of my webpack config with loaders and entry points:

     entry: { index: "./index.js", pug: glob.sync([path.join(__dirname + '/*.pug')]) } , output: { path: __dirname, filename: "[name].js" }, module: { loaders: [{ test: /\.pug/, loader: 'pug' } 

But when trying to build a webpack, it starts to build a project endlessly.

How to work with templates in the project? Can my method work? Where am I making mistakes?

  • Well, the fact that specifying patterns with dots inlet is very dumb , it's obvious. I did not encounter such a problem, one of the solutions is to look for some loader that knows how to set the glob in import - Duck Learns to Take Cover
  • Brief googling here: npmjs.com/package/import-glob , but few stars and have not tried it myself - Duck Learns to Take Cover
  • @ Moderately Punching You help me out again. Yes, I immediately wrote about entry point templates that it looks bad. - while1pass
  • @Morely tilting "did not encounter a problem." do you work with templates? or do you have a virtual home? - while1pass
  • You can also look at this: github.com/Aintaer/import-glob-loader . But pay attention, all this stuff is not very popular, maybe everything is simple and stupid like a clock, and maybe not - Duck Learns to Take Cover

0