What happen in rebuilding when config file changed

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

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:

and for hbs is :

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 .

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