background:
using ember cli 3.17
dev a babel plugin for replace some ENV variable and config CONST
GitHub - houfeng0923/ember-cli-global-env: support global env const in js and hbs for ember app.
hi, i have a problem when developing an ember cli addon , like ember-cli-global-env.
now, it looks work well . then i want to increase development experience ,
i hope reload latest config when config/global-env.js or config/environment.js changed , but i have no idea to do, i can’t find any addon hook invoked in rebuilding .
usually , when environment.js changed in dev, watcher can print ‘file changed xxxxx’ , and rebuild,
but latest config in environment not reload yet . how can resolve it ?
i want u a help or idea . thank u
ef4
May 25, 2020, 5:50am
2
I think you are having a problem with the caching in broccoli-babel-transpiler.
There is a way to tell it that your transformation depends on inputs other than the source code that’s being transpiled: GitHub - babel/broccoli-babel-transpiler at 09506f3b7f31b194a79f3eb5f1a81d2ac0336f10
If you generate a cacheKey based on the contents of the config file, that may solve the problem.
1 Like
thank you .
i have a check about cache . but i think it’s not the point .
in actual, ember-cli-global-env can work well , when env config update before restart ember s
.
babel plugins for broccoli can cache it correctly i think , because the options is right:
this.app = this._findHost();
const options = Object.assign({
helperName: 'env',
importPath: '@global/env',
},this.app.options['global-env']);
const globalEnv = this.createEnv(this.app.env, this.app.project);
this.addBabelPluginIfNotPresent(
'babel-plugin-replace-global-env',
{ env: {
[options.importPath]: globalEnv
} },
{ before: ['module:ember-auto-import'] }
);
registry.add('htmlbars-ast-plugin', {
name: 'remove-global-env-helper',
plugin: this.removeGlobalEnvPlugin(globalEnv, options.helperName),
baseDir() {
return __dirname;
}
and for hbs is :
}
}
}
});
return ast;
};
RemoveGlobalEnvHelperPlugin.toJSON = function() {
return {
[RemoveGlobalEnvHelperPlugin.name]: options
}
};
RemoveGlobalEnvHelperPlugin.parallelBabel = {
requireFile: __filename,
buildUsing: 'self',
};
return RemoveGlobalEnvHelperPlugin;
};
My expect case is : change config/* file, and hot re-compile correctly. not restart ember s
or ember build
.
but i think the cacheKey() only execute once . ? so i have no idea .
adong
November 1, 2020, 10:21pm
4
I have a similar case for local.js
. Here’s how I solved it.
In your config/environment.js
delete require.cache[require.resolve('./local.js')];
const localAppConfig = require('./local.js');
I believe this is an issue in caching node modules. Not sure is it caused by ember-cli or broccoli though.
1 Like