Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.bemrc.js support #20

Open
awinogradov opened this issue Jan 16, 2017 · 11 comments
Open

.bemrc.js support #20

awinogradov opened this issue Jan 16, 2017 · 11 comments

Comments

@awinogradov
Copy link

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
Copy link
Contributor

qfox commented Apr 22, 2017

You need specifically .js extension?

@awinogradov
Copy link
Author

I need possibility to require it ;)

@awinogradov awinogradov changed the title .bemrc.js support .bem.js support May 6, 2017
@tadatuta
Copy link
Member

tadatuta commented May 6, 2017

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 awinogradov changed the title .bem.js support .bemrc.js support May 6, 2017
@awinogradov
Copy link
Author

  1. Prebuild config in build time

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

@tadatuta
Copy link
Member

tadatuta commented May 6, 2017

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
Copy link
Member

Yeti-or commented May 6, 2017

@tadatuta could it be postinstall step ?

@awinogradov
Copy link
Author

@tadatuta it sounds good ;)

@tadatuta
Copy link
Member

tadatuta commented Jul 1, 2017

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
Copy link
Contributor

veged commented Sep 1, 2017

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

@awinogradov
Copy link
Author

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

@awinogradov
Copy link
Author

bem/bem-react#133

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants