GithubHelp home page GithubHelp logo

Deployment about webpacker HOT 8 CLOSED

rails avatar rails commented on May 5, 2024
Deployment

from webpacker.

Comments (8)

johnmaxwell avatar johnmaxwell commented on May 5, 2024 2

Reason dev dependencies get installed is that both rails and your rake task run yarn without the --production flag, which is the flag that skips dev dependencies. Not sure if that is intended or not?

I'm running into this right now. I'm using Vue, which uses the NODE_ENV environment var to determine if it should be run in production mode or not. (When I'm deploying, I want it in production mode.) When I set NODE_ENV to production on the production server and deploy, it will fail to build the pack because webpack, et al are "devDependencies" and not "dependencies" in package.json

What is the intended deployment strategy for webpacker? Based on the way webpacker compilation is tagged onto the assets:precompile rake task, it seems like the idea is that we compile on the webpacker assets on deployment server during deployment -- like the assets pipeline assets. Is that correct?

from webpacker.

jensljungblad avatar jensljungblad commented on May 5, 2024

Also wondering about this commit: 5afa882

If webpack etc are installed as dev dependencies, they won't be installed on, say Heroku. Does that mean you think assets should be built in a dev environment prior to deploying?

from webpacker.

joerodrig avatar joerodrig commented on May 5, 2024
  • Creating a blank yarn.lock file in your root directory tricks Heroku into installing Yarn.

  • For compiling your assets before deploying, you can create a rake task. Below is what I've been building off of:

# assets.rake
Rake::Task["assets:precompile"]
  .clear_prerequisites
  .enhance(["assets:compile_environment"])

namespace :assets do
  task compile_environment: [:yarn, :webpack] do
    Rake::Task["assets:environment"].invoke
  end

  desc "Install node deps via yarn"

  task :yarn do
    sh "bundle exec ./bin/yarn"
  end

  task :webpack do
    sh "bundle exec rails webpacker:compile"
  end
end
  • I haven't hit any issues deploying to Heroku with webpack listed as a devDependency, but admittedly, I haven't really looked into why!

from webpacker.

jensljungblad avatar jensljungblad commented on May 5, 2024

@joerodrig3 Do you need the nodejs build pack on Heroku as well? I can't get it to work even with an empty yarn.lock file in the root directory.

from webpacker.

joerodrig avatar joerodrig commented on May 5, 2024

Yep, any app that uses node needs the nodejs buildpack on Heroku: heroku/nodejs

from webpacker.

jensljungblad avatar jensljungblad commented on May 5, 2024

Thanks, got it working with the node build pack. Wonder if it would make sense to add node and yarn to the Heroku ruby build pack? I guess a Rails 5.1 app won't function correctly without it?

I grabbed this from rails master which is similar to what you suggested: https://github.com/rails/rails/blob/f04a49b033e3da54a52f76289863ec87a3c30438/railties/lib/rails/tasks/yarn.rake

Reason dev dependencies get installed is that both rails and your rake task run yarn without the --production flag, which is the flag that skips dev dependencies. Not sure if that is intended or not?

from webpacker.

joerodrig avatar joerodrig commented on May 5, 2024

In #72 dhh stated:

Heroku can update their Yarn detection in time.

So I am going to assume we'll have to wait and see what Heroku does :) Until then the Yarn hack seems like the only way to go. Custom buildpacks may help too. On a work project we did end up modifying one buildpack to fix a ruby version conflict we were having with Webpacker

from webpacker.

jensljungblad avatar jensljungblad commented on May 5, 2024

Sounds good!

from webpacker.

Related Issues (20)

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.