新手问题 Mina deploy Rails with Vue 出错

honglix · February 14, 2020 · Last by Rei replied at February 16, 2020 · 2074 hits

我试着把 Vue 引入 Rails 项目,用 Mina deploy 现在会出错误,是 deploy.rb 的配置问题吗?

task :deploy do
  deploy do
    comment "Deploying #{fetch(:application_name)} to #{fetch(:domain)}:#{fetch(:deploy_to)}"
    command %{ssh-agent}
    command %{rvm use 2.4}
    # command %{gem install bundler}
    invoke :'git:clone'
    invoke :'deploy:link_shared_paths'
    # invoke :'rvm:load_env_vars'
    invoke :'bundle:install'
    invoke :'rails:db_migrate'
    # command %{bundle exec rails db:migrate RAILS_ENV=production}
    # command %{#{fetch(:rails)} db:seed}
    command %{#{fetch(:rails)} webpacker:install:vue}
    invoke :'rails:assets_precompile'
    invoke :'deploy:cleanup'

webpacker:install:vue 是需要交互的命令,询问输入的适合卡住。

另外这个命令只需要在开发时跑一次,不需要在 deploy 的时候跑。

处理静态文件只需要 rails:assets_precompile 就行了。

Reply to Rei

谢谢,但如果只跑 rails:assets_precompile,mina deploy 后为什么我没看到 Vue 的组件加载到页面上啊

开发的时候在本地跑 rails webpacker:install:vue,会把 vue 依赖写进前端的依赖配置文件 package.json,并且在 webpack entry 里面 require 相关的库。

部署的时候跑 rails assets:precompile,会根据 package.json 安装相关依赖,并且编译 webpack entry。

检查下哪步有问题。

You need to Sign in before reply, if you don't have an account, please Sign up first.