N
N
Nikita Sokolov2019-11-22 16:52:40
BEM
Nikita Sokolov, 2019-11-22 16:52:40

Is it possible to auto-import BEM blocks in webpack?

Let's say I have a bunch of blocks and the same bunch of pages... How do I create entry points for them? For each page to register imports? Is it possible to auto-import BEM blocks that are used on the page? Is there any loader for this? Or is it all manual?
Now I'm using this script:

let files = []; 

function importAll(r) {
    r.keys().forEach((s, i) => {
        files[i] = r(s);
    });
}

importAll(require.context('../blocks/', true, /(\.less|\.js)$/));

But it imports all blocks at once

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question