Open awinogradov opened 7 years ago
You need specifically .js
extension?
I need possibility to require it ;)
We have two options to make it possible to browserify config:
betterc
)
- Prebuild config in build time
Is it about magic before this config will be in code? How should it work?
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.
@tadatuta could it be postinstall step ?
@tadatuta it sounds good ;)
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) + ';');
another solution may be a usage of process.env
and proxy to env in Webpack config
We need to use this one https://webpack.js.org/plugins/environment-plugin/
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 :(