bem-sdk-archive / bem-config

⚙ Config module for bem-tools: DEPRECATED →
https://github.com/bem/bem-sdk/tree/master/packages/config#bem-config
Other
7 stars 2 forks source link

.bemrc.js support #20

Open awinogradov opened 7 years ago

awinogradov commented 7 years ago

It will be awesome if we support .bemrc.js and the way to work with bem-config in commonJS modules witch will be browserified. It means we need support the way to work without critical dependencies, such as: fs, glob and etc. Only commonJS. It's required thing for bem-react-core. Yes, I know we can write some magic code for bundles and use in runtime, but it's not a better way, because it will be global objects :(

qfox commented 7 years ago

You need specifically .js extension?

awinogradov commented 7 years ago

I need possibility to require it ;)

tadatuta commented 7 years ago

We have two options to make it possible to browserify config:

  1. Separate everything about FS lookup (e.g. betterc)
  2. Prebuild config in build time
awinogradov commented 7 years ago
  1. Prebuild config in build time

Is it about magic before this config will be in code? How should it work?

tadatuta commented 7 years ago

Is it about magic before this config will be in code? How should it work?

What about something like this:

./node_modules/.bin/bem-config make-me-magic-please (or something similar with JS API). As a result new file will be generated with all the needed data from all found .bemrc already merged and easy to use with just object lookups and without any additional runtime API needed. So it can be plain JSON and all you need to do afterwards is just to include this config to your client JS somehow.

Yeti-or commented 7 years ago

@tadatuta could it be postinstall step ?

awinogradov commented 7 years ago

@tadatuta it sounds good ;)

tadatuta commented 7 years ago

After more consideration we end up with following solution.

Each project should create custom script to run in build time. There should be something like this:

const cfg = require('bem-config')();

const clientConfig = {
    levelMap: cfg.levelMapSync(),
    webpackBemLoader: cfg.moduleSync('webpack-bem-loader')
};

fs.writeFileSync('client-config.js', 'module.exports = ' + JSON.stringify(clientConfig) + ';');
veged commented 7 years ago

another solution may be a usage of process.env and proxy to env in Webpack config

awinogradov commented 7 years ago

We need to use this one https://webpack.js.org/plugins/environment-plugin/

awinogradov commented 7 years ago

https://github.com/bem/bem-react-core/issues/133