linnovate / meanio

meanio core module
MIT License
54 stars 73 forks source link

Make it possible to mark packages inactive for specific environments #121

Open ADSKLowenthal opened 8 years ago

ADSKLowenthal commented 8 years ago

Probably using the different configs per environment, we should allow some modules to not be loaded by MeanIO. This could be helpful for special logging packages, or debugging packages.

timelf123 commented 7 years ago

Part of this request (feature flags, or toggling code by env) could be hacked around now by setting globals with webpack and DefinePlugin, but it means wrapping every file in the package in an if statement, and only works on public/frontend files. Also will still process import statements at the top of files (afaik you are not allowed to do conditional imports by design of the import API), so really only works if using require/require.ensure

new webpack.DefinePlugin({
  'process.env':{
    'NODE_ENV': JSON.stringify(process.env.NODE_ENV),
  }
})
if (process.env.NODE_ENV === 'production) {
  angular code here
}
timelf123 commented 7 years ago

It looks like this may be already present in the source?

function findModules(meanioinstance, defer, app) {
    var disabled = _.toArray(meanioinstance.getConfig().disabledModules);
    Q.all([
        search(_modules, disabled, 'packages'),
        search(_modules, disabled, 'packages/core'),
        search(_modules, disabled, 'packages/custom'),
        search(_modules, disabled, 'packages/contrib'),
        search(_modules, disabled, 'node_modules')
    ]).done(findModulesDone.bind(null, meanioinstance, app, defer), findModulesError.bind(null, defer));
}

https://github.com/linnovate/meanio/blob/master/lib/core_modules/module/index.js#L76