【问题标题】:Run rails-react with webpacker in production mode. assets:precompile takes very much time在生产模式下使用 webpacker 运行 rails-react。 assets:precompile 需要很长时间
【发布时间】:2019-04-17 15:21:42
【问题描述】:

我有一个关于 webpacker 的 rails-react 项目。它在开发模式下完美运行,但我无法在生产模式下运行。

我在 docker 容器中运行它:

FROM ruby:2.5.1
# Install dependencies
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev
RUN apt-get update \
    && apt-get install -y xvfb qt5-default libqt5webkit5-dev \
                          gstreamer1.0-plugins-base gstreamer1.0-tools gstreamer1.0-x

# Node.js
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - \
    && apt-get install -y nodejs

# yarn
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -\
    && echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
    && apt-get update \
    && apt-get install -y yarn
# Adding gems
COPY Gemfile Gemfile
COPY Gemfile.lock Gemfile.lock
RUN bundle install

# Adding project files
COPY . .
RUN yarn install
RUN bundle exec rails assets:precompile
RUN bundle exec rails webpacker:compile

这是我的config/environments/production.rb 文件

  config.cache_classes = false
  config.eager_load = false
  config.consider_all_requests_local = false
  if Rails.root.join('tmp', 'caching-dev.txt').exist?
    config.action_controller.perform_caching = true
    config.cache_store = :memory_store
    config.public_file_server.headers = {
        'Cache-Control' => "public, max-age=#{2.days.to_i}"
    }
  else
    config.action_controller.perform_caching = false
    config.cache_store = :null_store
  end
  config.active_storage.service = :local
  config.action_mailer.raise_delivery_errors = false
  config.action_mailer.perform_caching = false
  config.active_support.deprecation = :log
  config.active_record.migration_error = :page_load
  config.active_record.verbose_query_logs = true
  config.assets.debug = true
  config.assets.compile = false
  config.assets.compress = true
  config.assets.logger = Logger.new $stdout
  config.assets.quiet = true

当我尝试在本地计算机上运行 rails assets:precompile 时,大约需要 1 小时,但没有任何反应。 当我尝试运行 docker 时,它说Your Yarn packages are out of date! 并建议进行纱线安装。我什至尝试删除 yarn.lock 文件。

下面是我的 webpacker.yml 配置:

production:
  source_path: app/javascript
  source_entry_path: packs
  public_output_path: packs
  cache_path: tmp/cache/webpacker
  resolved_paths: []
  extensions:
    - .tsx
    - .ts
    - .mjs
    - .jsx
    - .js
    - .sass
    - .scss
    - .css
    - .module.sass
    - .module.scss
    - .module.css
    - .png
    - .svg
    - .gif
    - .jpeg
    - .jpg
  compile: false
  cache_manifest: true

任何帮助都会很有用,因为我没有太多使用 webpacker 的经验。

【问题讨论】:

    标签: ruby-on-rails reactjs typescript webpack production-environment


    【解决方案1】:

    你需要在你的 webpacker.yml 中添加

    check_yarn_integrity: false
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-16
      • 2017-05-03
      • 2015-04-11
      • 1970-01-01
      • 2020-03-18
      • 2013-10-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多