Skip to content

Conversation

gauravtiwari
Copy link
Member

@gauravtiwari gauravtiwari commented Apr 29, 2017

Summary

// cc @rafaelfranca @dhh

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where webpacker uses action view? One of the uses cases for webpacker is exacly API applications that want to use client side frameworks.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rafaelfranca Webpacker has view helpers like javascript_pack_tag etc. which won't work without views. I guess --api skips that right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can add support to make it work independently without Rails views though 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only way of using webpacker is with javascript_pack_tag? Is it not possible to user webpacker and don't use those helpers?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is possible to use, but there is no out of the box support like helpers to link those webpack bundles. If someone wants to add this they have to install HTML plugin and add some changes to make this work

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The gem does two things - one is using Webpack to compile modern javascript code and two involves helpers to fetch and link them within Rails views. Perhaps with api option supplied together with webpack we can re-structure bits of webpacker gem so that it serve files directly from public directory.

@gauravtiwari
Copy link
Member Author

Sorry for such yarn travis dance. Seems like it simply doesn't work on travis with container-builds - https://yarnpkg.com/lang/en/docs/install-ci/#travis-tab.

screen shot 2017-04-29 at 18 29 24

@maclover7
Copy link
Contributor

This seems like a duplication of the check_node and check_yarn tasks in webpacker. Is the issue that rails new isn't failing the right way when webpacker is checking dependencies?

@gauravtiwari
Copy link
Member Author

@maclover7 That's correct. I think with --webpack option supplied rails new should fail hard. At the moment it goes up to the point of running webpacker:install and fails there, which isn't great because then the whole app structure is in place and you have to manually run webpacker:install or delete the app and re-run rails new. What do you think?

@gauravtiwari
Copy link
Member Author

Webpacker check is useful for independent gem install. Obviously, one downside is with rails new --webpack we are checking this twice.

@maclover7
Copy link
Contributor

Hmm, spent some time digging around the docs for generators, and may have found a solution. Can you wrap the entire webpacker installer template and the JS dependency checks in an after_bundle callback? I think that would ensure it's the last thing that runs, so it wouldn't bounce people out early from rails new.

@gauravtiwari
Copy link
Member Author

@maclover7 It says in the doc that after_bundle callback gets executed even if --skip-bundle and/or --skip-spring has been passed. Don't you think that will lead to the same issue we are having now? i.e. it will try to run webpacker:install anyway unless I am missing something :)

@maclover7
Copy link
Contributor

@gauravtiwari Sorry, I didn't fully say what I was thinking 😞 How about we keep the webpacker + skip bundle stuff in the app generator (this is more a concern of rails than webpacker), and then move the dependency stuff and the install task to the after_bundle hook.

@gauravtiwari
Copy link
Member Author

@maclover7 No worries :) after_bundle looks great although I am not sure how it would help if say yarn isn't installed on the system and then rails new generates the project structure without failing until webpacker:install. Do you think we shouldn't fail if yarn or node isn't installed and --webpack option is supplied inside app generator?

@gauravtiwari
Copy link
Member Author

@rafaelfranca @maclover7 Removed the yarn and node check part. Good enough for merge?

@gauravtiwari gauravtiwari changed the title Add system checks if --webpack flag is set in rails new Fail hard if incompatible options are supplied with --webpack May 23, 2017
@maclover7
Copy link
Contributor

maclover7 commented May 24, 2017

@gauravtiwari Since we aren't doing raising for bad versions, where is that happening now? Within webpacker? Is that out of scope now for this PR?

@gauravtiwari
Copy link
Member Author

@maclover7 Yepp that will happen inside webpacker - seems like best thing to do at this point.

Copy link
Contributor

@maclover7 maclover7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you squash down to one commit?

@gauravtiwari
Copy link
Member Author

@maclover7 Done!

Looks like rb-notify was force pushed or something because I was getting this error on initial bundle fatal: Could not parse object '90553518d1fb79aedc98a3036c59bd2b6731ac40' so bundled it to latest revision.

# --webpack requires webpacker gem to be pre-bundled
# --skip-bundle skips bundle install
if options[:webpack] && options[:skip_bundle]
raise Error, "Incompatible options --webpack and --skip-bundle supplied. Please use either --skip-bundle or --webpack"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we fail in this case or just skip the wepacker:install call that we do later? I always generate my applications with --skip-bundler (it is in my ~/.railsrc) and I'm fine with adding webpacker in my gemfile when using --webpack and running webpacker:install manually. But the fact that I can't do that when we merge this code annoys me.

@rails-bot
Copy link

rails-bot bot commented Dec 18, 2019

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Thank you for your contributions.

@rails-bot rails-bot bot added the stale label Dec 18, 2019
@rails-bot rails-bot bot closed this Dec 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants