Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Plugin improvement: expose truffle-core's index.js in webpack bundle #2222

Closed
cgewecke opened this issue Jul 16, 2019 · 5 comments
Closed

Plugin improvement: expose truffle-core's index.js in webpack bundle #2222

cgewecke opened this issue Jul 16, 2019 · 5 comments

Comments

@cgewecke
Copy link
Contributor

cgewecke commented Jul 16, 2019

As a plugin I might like to compile with special settings or run tests after preprocessing something. It would be convenient to have all the resources exported in truffle-core's index.js immediately available with

const truffle = require("truffle");

Not sure but I think this is possible with webpack's expose-loader. Like maybe you just have to expose truffle-core as index.js and list the bundled cli.js as the package.json's main?

Questions

  • Is this already possible but I've missed it?
  • If not, Is there any appetite for a PR like this?
  • If it becomes possible, should any additional truffle modules be exposed?
@gnidan
Copy link
Contributor

gnidan commented Jul 16, 2019

issue number with all 2's, nice @cgewecke

Is this file actually useful in its current state? I barely even knew it existed.

Anyway, just as a quick response:

Is this already possible but I've missed it?

I haven't looked, but the solution you describe sounds viable, or maybe it's simpler than that... you might only need to define another entrypoint in the webpack config.

If not, Is there any appetite for a PR like this?

I'd be in favor of getting Truffle available as a library!

If it becomes possible, should any additional truffle modules be exposed?

Probably! I think maybe it's worth collecting use cases here? It wouldn't be awful, but it'd be a shame to suddenly offer Truffle as a library only to have to break the interface quickly afterwards.

@cgewecke
Copy link
Contributor Author

@gnidan Whoa! I didn't notice that about the 2's'. Crazy!

I don't know about other use cases but mine is coverage. I need to:

  • set the provider as a ganache-core instance (so I can listen to the vm step and watch opcodes)
  • compile from a custom contracts_directory with optimization.enabled: false to a custom build_directory.
  • execute the tests using the artifacts written to the custom buid_directory.

I think if I have workflow-compile and truffle-core/lib/test I'm good, idk.

define another entrypoint in the webpack config.

Apologies, could you explain that to me?

@gnidan
Copy link
Contributor

gnidan commented Jul 16, 2019

define another entrypoint in the webpack config.

See this part of the webpack config, which defines cli, chain, analytics, getting bundled into cli.bundled.js, etc. I think you just need to add to that and specify a main in the package.json? Try it out, though.

...

Thinking about this some more... I don't think the risk of breaking change is that big of a deal. Might as well get any kind of useful interface now and worry about a proper interface later. Feel free to open a PR!*

(*fyi tho i'm afk for the next week, so i'll have to review/merge when i get back, if no one else beats me to it)

Thanks for calling attention to this!

@cgewecke
Copy link
Contributor Author

cgewecke commented Jul 16, 2019

Sweet thank you and no problem I'm doing all this way in advance. Have a great vacation.

Was worried that doing it the analytics.js way might make another huge mostly duplicate bundle. Which is fine with me but will look into the other way anyway....

I don't think the risk of breaking change is that big of a deal.

Probably compile and test will be pretty standard inclusions no matter what. . .I think it's pretty safe.

@cgewecke
Copy link
Contributor Author

Published in 5.0.30

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants