├── LICENSE.md ├── README.md └── bin ├── compile └── detect /LICENSE.md: -------------------------------------------------------------------------------- 1 | Portions copyright (c) 2016 Florian Ebeling 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # webpack-rails-buildpack 2 | 3 | A buildpack to support Heroku deployments for applications using [webpack-rails](https://github.com/mipearson/webpack-rails). 4 | 5 | Name on [Heroku's buildpack registry](https://devcenter.heroku.com/articles/buildpack-registry): __febeling/webpack-rails__ 6 | 7 | _Note: Now that Rails (>= 5.1) has the webpacker gem there are few reasons to use this buildpack. 8 | The default Heroku Ruby buildpack can handle webpacker, too._ 9 | 10 | ## Installation 11 | 12 | #### Heroku Dashboard 13 | 14 | Add a custom buildpack to your to your application's Settings tab 15 | under section Buildpacks by using the URL of this repository, instead 16 | of the short name of Heroku's own buildpacks. It goes alongside your 17 | Ruby and Node buildpacks, placed in last position. 18 | 19 | After the release of registered buildpacks, it will be available under 20 | the name `febeling/webpack-rails`, adhearing to the suggested naming 21 | conventions there. 22 | 23 | #### Heroku CLI 24 | 25 | First, check your Heroku app has the Ruby and Node buildpacks added, 26 | in the command line run: 27 | 28 | heroku buildpacks 29 | 30 | If they are added you should see: 31 | 32 | your-app-1234 Buildpack 33 | 1. heroku/nodejs 34 | 2. heroku/ruby 35 | 36 | To add the Webpack Rails buildpack in the last index, run this command: 37 | 38 | heroku buildpacks:add --index 3 febeling/webpack-rails 39 | 40 | ## Usage 41 | 42 | On deployment, the buildpack runs the build command `bundle exec rake 43 | webpack:compile`. Under default configuration that will output the 44 | compiled assets under `public/webpack`. 45 | 46 | ### Package Manager 47 | 48 | Heroku supports both NPM and Yarn as Javascript package managers. This 49 | buildpack will detect which one to use automatically, based on the 50 | persence of a version-lock file. Projects that use yarn have a 51 | `yarn.lock` file, while those that use npm have a `package-lock.json` 52 | (or none if using an older version of `npm`). 53 | 54 | This buildpack will set the `YARN` environment variable accordingly, which 55 | will make that the effective package manager for Javascript. 56 | 57 | ## Using the latest buildpack code 58 | 59 | The `febeling/webpack-rails` buildpack from the [Heroku 60 | Registry](https://devcenter.heroku.com/articles/buildpack-registry) 61 | contains the latest stable version of the buildpack. If you'd like to 62 | use the latest buildpack code from this Github repository, you can set 63 | your buildpack to the Github URL: 64 | 65 | heroku buildpacks:add --index 3 https://github.com/febeling/webpack-rails-buildpack 66 | 67 | ## Contributing 68 | 69 | 1. Fork it! 70 | 2. Create your feature branch: `git checkout -b my-new-feature` 71 | 3. Commit your changes: `git commit -am 'Add some feature'` 72 | 4. Push to the branch: `git push origin my-new-feature` 73 | 5. Submit a pull request :D 74 | 75 | ## History 76 | 77 | Started on 5 June 2016. 78 | 79 | ## Credits 80 | 81 | Created by Florian Ebeling. 82 | 83 | ## License 84 | 85 | See LICENSE.md file. 86 | -------------------------------------------------------------------------------- /bin/compile: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # -*- shell-script -*- 3 | 4 | # Run the webpack-rails rake task `webpack:compile`. 5 | # 6 | # This compiles assets to `public/webpack` when using default 7 | # configuration. 8 | 9 | set -o errexit # exit on error 10 | 11 | build_dir=$1 12 | cache_dir=$2 13 | env_dir=$3 14 | 15 | cd $build_dir 16 | 17 | if [ -f "$build_dir/yarn.lock" ]; then 18 | YARN=true 19 | else 20 | YARN=false 21 | fi 22 | 23 | detect_package_manager() { 24 | case $YARN in 25 | true) echo "yarn";; 26 | *) echo "npm";; 27 | esac 28 | } 29 | 30 | # This function loads the Heroku settings variables from the files in 31 | # `env_dir` and sets the up as environment variables. 32 | export_env_dir() { 33 | whitelist_regex=${2:-''} 34 | blacklist_regex=${3:-'^(PATH|GIT_DIR|CPATH|CPPATH|LD_PRELOAD|LIBRARY_PATH)$'} 35 | if [ -d "$env_dir" ]; then 36 | for e in $(ls $env_dir); do 37 | echo "$e" | grep -E "$whitelist_regex" | grep -qvE "$blacklist_regex" && 38 | export "$e=$(cat $env_dir/$e)" 39 | : 40 | done 41 | fi 42 | } 43 | 44 | export_env_dir 45 | 46 | echo "-----> gem install bundler (if missing)" 47 | gem which bundler >/dev/null 2>&1 || gem install bundler --no-document -v '~> 1.17' --force 48 | 49 | echo "-----> bundle install" 50 | bundle install -j4 --deployment 51 | 52 | echo "-----> " detect_package_manager " install" 53 | 54 | if $YARN; then 55 | yarn install 56 | else 57 | npm install 58 | fi 59 | 60 | echo "-----> bundle exec rake webpack:compile" 61 | bundle exec rake webpack:compile --trace 62 | 63 | if ! $YARN; then 64 | echo "-----> npm prune" 65 | npm prune 66 | fi 67 | -------------------------------------------------------------------------------- /bin/detect: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # -*- shell-script -*- 3 | 4 | # Assume this project uses webpack-rails gem if it depends 5 | # on the webpack-rails gem (or just mentions it). 6 | # 7 | # `grep` will set the significant exit code accordingly. 8 | 9 | echo "webpack-rails" 10 | 11 | build_dir=$1 12 | 13 | grep 'webpack-rails' < $build_dir/Gemfile > /dev/null 14 | --------------------------------------------------------------------------------