简体   繁体   English

如何在另一台机器上使用 Webpacker 和 React 设置 Rails 项目?

[英]How to setup a Rails project with Webpacker and React on another machine?

I've got a Rails 6 project that I am doing by following the book Agile Web Development with Rails 5.1, and I am using Circle CI for the build and tests.我有一个 Rails 6 项目,我正在按照这本书使用 Rails 5.1 进行敏捷 Web 开发,并且我正在使用 Circle CI 进行构建和测试。 I will basically list all my questions at the end of the post.我基本上会在帖子末尾列出我所有的问题。

Below is the part where I install webpacker in my circle.yml下面是我在circle.yml中安装 webpacker 的部分

- run:
    name: Install webpacker
    command: bundle exec rails webpacker:install

That was fine until we've installed React.这很好,直到我们安装了 React。 We've installed React using rails webpacker:install:react .我们已经使用rails webpacker:install:react安装了 React。 After installing React, I push the code to GitHub and then CircleCI starts building the environment however when it tries to install webpacker I get this conflict below:安装 React 后,我将代码推送到 GitHub,然后 CircleCI 开始构建环境,但是当它尝试安装webpacker时,我在下面遇到了这个冲突:

    conflict  config/webpacker.yml
rails aborted!rs/burak/git/agile-rails/config/webpacker.yml? (enter "h" for help) [Ynaqdhm]

You can see what happens below if I say "yes" to this.如果我对此说“是”,您可以在下面看到会发生什么。

╰─$ rails webpacker:install
Warning: you are using an unstable release of Node.js (v15.14.0). If you encounter issues with Node.js, consider switching to an Active LTS release. More info: https://docs.npmjs.com/try-the-latest-stable-version-of-node
    conflict  config/webpacker.yml
Overwrite /Users/burak/git/test/agile-rails/config/webpacker.yml? (enter "h" for help) [Ynaqdhm] Y
       force  config/webpacker.yml
Copying webpack core config
       exist  config/webpack
   identical  config/webpack/development.js
   identical  config/webpack/environment.js
   identical  config/webpack/production.js
   identical  config/webpack/test.js
Copying postcss.config.js to app root directory
   identical  postcss.config.js
Copying babel.config.js to app root directory
    conflict  babel.config.js
Overwrite /Users/burak/git/test/agile-rails/babel.config.js? (enter "h" for help) [Ynaqdhm] Y
       force  babel.config.js
Copying .browserslistrc to app root directory
   identical  .browserslistrc
The JavaScript app source directory already exists
       apply  /Users/burak/.rvm/gems/ruby-2.7.3/gems/webpacker-5.2.1/lib/install/binstubs.rb
  Copying binstubs
       exist    bin
   identical    bin/webpack
   identical    bin/webpack-dev-server
File unchanged! The supplied flag value not found!  .gitignore
Installing all JavaScript dependencies [5.2.1]
         run  yarn add @rails/webpacker@5.2.1 from "."
yarn add v1.22.10
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
warning " > @babel/preset-react@7.13.13" has unmet peer dependency "@babel/core@^7.0.0-0".
warning "@babel/preset-react > @babel/plugin-transform-react-display-name@7.12.13" has unmet peer dependency "@babel/core@^7.0.0-0".
warning "@babel/preset-react > @babel/plugin-transform-react-jsx@7.13.12" has unmet peer dependency "@babel/core@^7.0.0-0".
warning "@babel/preset-react > @babel/plugin-transform-react-jsx-development@7.12.17" has unmet peer dependency "@babel/core@^7.0.0-0".
warning "@babel/preset-react > @babel/plugin-transform-react-pure-annotations@7.12.1" has unmet peer dependency "@babel/core@^7.0.0-0".
warning "@babel/preset-react > @babel/plugin-transform-react-jsx > @babel/plugin-syntax-jsx@7.12.13" has unmet peer dependency "@babel/core@^7.0.0-0".
warning " > webpack-dev-server@3.11.2" has unmet peer dependency "webpack@^4.0.0 || ^5.0.0".
warning "webpack-dev-server > webpack-dev-middleware@3.7.3" has unmet peer dependency "webpack@^4.0.0 || ^5.0.0".
[4/4] 🔨  Building fresh packages...
[-/3] ⠈ waiting...
success Saved 0 new dependencies.
✨  Done in 50.91s.
Installing dev server for live reloading
         run  yarn add --dev webpack-dev-server from "."
yarn add v1.22.10
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
warning " > @babel/preset-react@7.13.13" has unmet peer dependency "@babel/core@^7.0.0-0".
warning "@babel/preset-react > @babel/plugin-transform-react-display-name@7.12.13" has unmet peer dependency "@babel/core@^7.0.0-0".
warning "@babel/preset-react > @babel/plugin-transform-react-jsx@7.13.12" has unmet peer dependency "@babel/core@^7.0.0-0".
warning "@babel/preset-react > @babel/plugin-transform-react-jsx-development@7.12.17" has unmet peer dependency "@babel/core@^7.0.0-0".
warning "@babel/preset-react > @babel/plugin-transform-react-pure-annotations@7.12.1" has unmet peer dependency "@babel/core@^7.0.0-0".
warning "@babel/preset-react > @babel/plugin-transform-react-jsx > @babel/plugin-syntax-jsx@7.12.13" has unmet peer dependency "@babel/core@^7.0.0-0".
warning "webpack-dev-server > webpack-dev-middleware@3.7.3" has unmet peer dependency "webpack@^4.0.0 || ^5.0.0".
warning " > webpack-dev-server@3.11.2" has unmet peer dependency "webpack@^4.0.0 || ^5.0.0".
[4/4] 🔨  Building fresh packages...
success Saved 1 new dependency.
info Direct dependencies
└─ webpack-dev-server@3.11.2
info All dependencies
└─ webpack-dev-server@3.11.2
✨  Done in 1.30s.
Webpacker successfully installed 🎉 🍰

So the React gets removed from the project if I say "yes" to overwrite, as far as I've understood.因此,据我所知,如果我说“是”来覆盖,那么 React 就会从项目中删除。 If I say "no" to overwrite then everything is fine.如果我说“不”覆盖,那么一切都很好。

  1. Does it make sense to run rails webpacker:install on another machine?在另一台机器上运行rails webpacker:install有意义吗? Isn't that command just installing webpacker for the project and not for the machine?该命令不只是为项目而不是机器安装 webpacker 吗?

  2. Instead of running rails webpacker:install and then saying "no" to overwrite I can do rails assets:precompile as well which works.而不是运行rails webpacker:install然后说“不”来覆盖我可以做rails assets:precompile也可以。 Which command do I need to use to be able to successfully setup a Rails project with Webpacker and React on another machine or could someone please show me the right way to set it up?我需要使用哪个命令才能成功地在另一台机器上使用 Webpacker 和 React 设置 Rails 项目,或者有人可以告诉我设置它的正确方法吗?

  1. Yes, you are trying to install webpacker for this project once again when you're running rails webpacker:install on the CI machine.是的,当您在 CI 机器上运行rails webpacker:install时,您正尝试再次为该项目安装 webpacker。
  2. Yes, what you need to run on another machine is rails assets:precompile .是的,您需要在另一台机器上运行的是rails assets:precompile What it does it compiles all your assets for production, not development use and that's exactly what you'd want on the non-development machine (CI, staging, production).它的作用是将所有资产编译用于生产,而不是用于开发用途,而这正是您在非开发机器(CI、登台、生产)上想要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM