I
I
Igor2016-08-08 14:03:47
webpack
Igor, 2016-08-08 14:03:47

How to create separate build files depending on folder?

Hello!
I have the following file structure:
App.js
locales
– en
–– MainMenu.yml
–– UserMenu.yml
–ru
–– MainMenu.yml
–– UserMenu.yml
I would like to dynamically include all files from the en and ru folders from App.js . And glue all the files inside each folder into one JSON string. And at the same time, avoid adding index.js to each directory with translation files.
So that in the end the assembly looks like this:
app.js
1.en.js
2.ru.js
How can this be implemented? Thank you!
UPD
So far I'm doing this, but I would also like to dynamically define folders with languages:

switch(locale){
  case 'en':
    require.ensure([], require => {
      context = require.context('../../locales/en/', true, /\.yml$/);
      this.loadTranslate(context);
    });
    break;
  case 'ru':
    require.ensure([], require => {
      context = require.context('../../locales/ru/', true, /\.yml$/);
      this.loadTranslate(context);
    });
    break;
}

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