Giter Club home page Giter Club logo

webpack-rails-buildpack's Introduction

webpack-rails-buildpack

A buildpack to support Heroku deployments for applications using webpack-rails.

Name on Heroku's buildpack registry: febeling/webpack-rails

Note: Now that Rails (>= 5.1) has the webpacker gem there are few reasons to use this buildpack. The default Heroku Ruby buildpack can handle webpacker, too.

Installation

Heroku Dashboard

Add a custom buildpack to your to your application's Settings tab under section Buildpacks by using the URL of this repository, instead of the short name of Heroku's own buildpacks. It goes alongside your Ruby and Node buildpacks, placed in last position.

After the release of registered buildpacks, it will be available under the name febeling/webpack-rails, adhearing to the suggested naming conventions there.

Heroku CLI

First, check your Heroku app has the Ruby and Node buildpacks added, in the command line run:

heroku buildpacks

If they are added you should see:

your-app-1234 Buildpack
1. heroku/nodejs
2. heroku/ruby

To add the Webpack Rails buildpack in the last index, run this command:

heroku buildpacks:add --index 3 febeling/webpack-rails

Usage

On deployment, the buildpack runs the build command bundle exec rake webpack:compile. Under default configuration that will output the compiled assets under public/webpack.

Package Manager

Heroku supports both NPM and Yarn as Javascript package managers. This buildpack will detect which one to use automatically, based on the persence of a version-lock file. Projects that use yarn have a yarn.lock file, while those that use npm have a package-lock.json (or none if using an older version of npm).

This buildpack will set the YARN environment variable accordingly, which will make that the effective package manager for Javascript.

Using the latest buildpack code

The febeling/webpack-rails buildpack from the Heroku Registry contains the latest stable version of the buildpack. If you'd like to use the latest buildpack code from this Github repository, you can set your buildpack to the Github URL:

heroku buildpacks:add --index 3 https://github.com/febeling/webpack-rails-buildpack

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

History

Started on 5 June 2016.

Credits

Created by Florian Ebeling.

License

See LICENSE.md file.

webpack-rails-buildpack's People

Contributors

arjeno avatar brunoarueira avatar cgc avatar conorcussell avatar febeling avatar jkutner avatar nickgsc avatar zinssmeister avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

webpack-rails-buildpack's Issues

Previous build not restored from cache, potentially causing 404s

There is an edge case where a page loads at the same time as the deploy switches from old to new dynos. The page contains references (e.g. <script>) to out-of-date assets from the previous deploy, but the client does not have time to download them before the dynos are switched.

The new dyno then does not contain these old assets and would therefore 404. The new dyno only contains assets from the new build. This could only happen in a very short window, however it could be exaggerated by slow/flaky connections.

If the previous deploy's output assets could be pulled from cache and persisted into the new dyno, the problem would be fixed. Note that it would be sensible to restrict this to only the last deploy's output, otherwise the cache may become bloated.

Unfortunately the buildpack doesn't know where the output assets be put, and thus can't move it into the cache. The only options that I could think of to resolve this would be to assume the use of an environment variable or to somehow introspect webpack itself to find the output directory. Do you think either of these are options that you would accept a PR for?

Make bundler version a range <2

Issue #19 pinned the bundler version on a specific one, to get around incompatibility with version 2, which was released today. We should change the version spec from specific to one that can float up to anything below 2.

nodejs webpack doesn't detect package.json file

I'm not sure if this is a problem with the heroku nodejs buildpack or with this project, but I figured I would start here. I'm attempting to use the webpack-rails gem (https://github.com/mipearson/webpack-rails) with an app hosted on github. The author links to this project as a way to include the running webpack server that's required for the gem in heroku. I have added the required buildpacks to my app and I have both a Gemfile and a package.json file in the root of my project directory, but heroku returns an error when I attempt to push to it (see gist for proof). I read the source for the official nodejs buildpack, and the detect script seems to be very simple. I tried forking the repo and adding some debugging, but heroku appears to swallow all output from the detect script. Is there another way to figure out what's going on?

Could not find bundler?

I added this buildpack:

=== app-staging Buildpack URLs
1. heroku/nodejs
2. heroku/ruby
3. https://github.com/febeling/webpack-rails-buildpack.git

When I deploy, I get an error related to using bundle exec

remote: -----> Fetching set buildpack https://github.com/febeling/webpack-rails-buildpack.git... done
remote: -----> webpack-rails app detected
remote: -----> bundle exec rake webpack:compile
remote: /tmp/build_e79d1dc4352be15c4a65c94ee432b514/vendor/ruby-2.2.3/lib/ruby/2.2.0/rubygems/dependency.rb:315:in `to_specs': Could not find 'bundler' (>= 0) among 9 total gem(s) (Gem::LoadError)
remote: Checked in 'GEM_PATH=vendor/bundle/ruby/1.9.1:/tmp/build_e79d1dc4352be15c4a65c94ee432b514/vendor/ruby-2.2.3/lib/ruby/gems/2.2.0', execute `gem env` for more information
remote:     from /tmp/build_e79d1dc4352be15c4a65c94ee432b514/vendor/ruby-2.2.3/lib/ruby/2.2.0/rubygems/dependency.rb:324:in `to_spec'
remote:     from /tmp/build_e79d1dc4352be15c4a65c94ee432b514/vendor/ruby-2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_gem.rb:64:in `gem'
remote:     from /tmp/build_e79d1dc4352be15c4a65c94ee432b514/vendor/bundle/ruby/2.2.0/bin/bundle:22:in `<main>'
remote: 
remote:  !     Push rejected, failed to compile webpack-rails app
remote: 

Any ideas?

Issue in first installation

Hi, I'm trying install using your instructions webpack-rails-buildpack
and receiving the error the last pat of it I want to share with you
...
remote: -----> bundle exec rake webpack:compile
remote: ** Invoke webpack:compile (first_time)
remote: ** Invoke environment (first_time)
remote: ** Execute environment
remote: ** Execute webpack:compile
remote: rake aborted!
remote: Can't find our webpack config file at /tmp/build_bf4a14785e9ae6614cc312a0e773388c/config/webpack.config.js
remote: /tmp/build_bf4a14785e9ae6614cc312a0e773388c/vendor/bundle/ruby/2.2.0/gems/webpack-rails-0.9.11/lib/tasks/webpack.rake:14:in `block (2 levels) in <top (required)>'
...

What was done wrong and how I can fix it?

NPM and Yarn Slapfight

It looks like this buildpack is hardcoded to use NPM instead of Yarn. We ran into a problem where Yarn was installing and respecting it's lockfile, but then NPM was coming through and installing without a lockfile, thereby overwriting some locked versions.

For the moment we just forked and removed the NPM install line. What would be the best course of action for detecting whether to use Yarn or NPM?

Bundler conflicts with ruby-2.6.1/bin/bundle

I'm using ruby 2.6.1 and bundler 2.0.1 for my ruby app.
When I was trying to deploy app I got the following error:

remote: -----> webpack-rails app detected
remote: -----> gem install bundler
remote: ERROR:  Error installing bundler:
remote: 	"bundle" from bundler conflicts with /tmp/build_5f23e64fd8050f5654d8fe6ab7e0bd8d/vendor/ruby-2.6.1/bin/bundle
remote:  !     Push rejected, failed to compile webpack-rails app.
remote:
remote:  !     Push failed

Is there any workaround to this issue?

Build failures installing bundler due to bundler 2.0 release

FYI, the explicit call to gem install bundler (introduced in #2) started causing build failures for us this morning as a result of Bundler releasing 2.0, which effectively has a breaking change in needing RubyGems 3.0:

-----> webpack-rails app detected
-----> gem install bundler
ERROR:  Error installing bundler:
	The last version of bundler (>= 0) to support your Ruby & RubyGems was 1.17.3. Try installing it with `gem install bundler -v 1.17.3`
	bundler requires RubyGems version >= 3.0.0. The current RubyGems version is 2.7.6. Try 'gem update --system' to update RubyGems itself.
 !     Push rejected, failed to compile webpack-rails app.
 !     Push failed

I believe a short-term fix for this would be to forcibly set the version to 1.x in the gem install command. I expect this will go away when Heroku formally supports Bundler 2.0/RubyGems 3.0 in the ruby buildpack.

`Can't find our webpack executable at` on Heroku

On thursday we started receiving this issue during the slug compilation on heroku.

** Execute webpack:compile
rake aborted!
Can't find our webpack executable at /tmp/build_8f0a62a90132b53a9b4b0536055c0a88/node_modules/.bin/webpack - have you run npm install?

Are there any issues you were aware of. Heroku are saying its an issue with the build pack and not heroku.

These are our current build packs:

  1. https://github.com/sofarsounds/heroku-buildpack-git-sha.git
  2. heroku/ruby
  3. heroku/nodejs
  4. https://github.com/febeling/webpack-rails-buildpack.git

As mentioned these were working but are not now.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.