embroider-build / embroider

Compiling Ember apps into spec-compliant, modern Javascript.
MIT License
337 stars 136 forks source link

Addons are not being rebuilt with livereload #1746

Closed TSenter closed 9 months ago

TSenter commented 9 months ago

I have a new v2 addon with the addon and test app as two subpackages. When I make a change to a component in the addon package, the running test app reloads, but the addon isn't rebuilt. The only way I can view the changes to the addon is by shutting down the ember s server, rebuilding the addon with pnpm build, and starting the server again.

TSenter commented 9 months ago

Reproduction repo: https://github.com/TSenter/embroider-addon-rebuild-reproduction

Jopie01 commented 9 months ago

I don't know if it's the correct way, but I have to run pnpm start in my addon as well. Take a look at the package.json in your addon and you'll see that pnpm start will start to watch for changes in your addon and rebuild the addon.

So I have two terminal windows open, one with pnpm start in my addon and one with ember serve in my test app. That way it works like expected.

TSenter commented 9 months ago

I don't know if it's the correct way, but I have to run pnpm start in my addon as well. Take a look at the package.json in your addon and you'll see that pnpm start will start to watch for changes in your addon and rebuild the addon.

So I have two terminal windows open, one with pnpm start in my addon and one with ember serve in my test app. That way it works like expected.

I didn't even realize that was a thing! I haven't seen many docs on Embroider addons yet, so I never even noticed. If @NullVoxPopuli or someone else can confirm that this is the correct way, I'll close this issue.

NullVoxPopuli commented 9 months ago

It is the correct way.

In particular, when looking at the root package.json of the blueprint, you'll see 3 start scripts:

"start": "concurrently 'npm:start:*' --restart-after 5000 --prefix-colors cyan,white,yellow",
"start:addon": "pnpm --filter macros-tests start --no-watch.clearScreen",
"start:test-app": "pnpm --filter test-app start",

And as is common with all libraries that need compiling, the library build runs in watch mode (start:addon), as does the test app (what you're used to).

There is no way for an app to build a library for you, as libraries have too much variation in how they are built. This would also defeat the purpose of the v2 addon effort in the first place, which is two parts:

I haven't seen many docs on Embroider addons yet

there's actually more docs on v2 addons than there are v1 addons:

And related:

TSenter commented 9 months ago

@NullVoxPopuli - I'll be amazed, I don't think I ever once looked at the root package.json. Thank you for the added information!

Also, by "lack of documentation" I suppose I was referring to my lack of experience with Rollup (and general inexperience with creating Node libraries). I think that's where most of my confusion came from. I had read a few of the documents you linked to, but I'll reread them in depth when I get to dig back into this addon.

Finally, thank you @Jopie01 for your quick insight! That was certainly able to get me moving in the right direction.