Javascript 如何在Rails中更改Webpack以监视packs文件夹之外的更改?

Javascript 如何在Rails中更改Webpack以监视packs文件夹之外的更改?,javascript,ruby-on-rails,ruby,webpack,webpacker,Javascript,Ruby On Rails,Ruby,Webpack,Webpacker,我希望热模块重新加载以重新加载JavaScript/React文件中的更改 我正在经历 在那上面写着 此过程将监视app/javascript/packs/*.js中的更改 现在,我想查看packs项目之外或整个javascript文件夹中的更改,还需要包括.jsx文件 我不知道怎样才能做到 这是我的webpacker文件: #/usr/bin/env ruby ENV['RAILS_ENV']| |=ENV['RACK_ENV']| | development' 环境['NODE_ENV']|

我希望热模块重新加载以重新加载JavaScript/React文件中的更改

我正在经历

在那上面写着

此过程将监视app/javascript/packs/*.js中的更改

现在,我想查看packs项目之外或整个
javascript
文件夹中的更改,还需要包括
.jsx
文件

我不知道怎样才能做到

这是我的
webpacker
文件:

#/usr/bin/env ruby
ENV['RAILS_ENV']| |=ENV['RACK_ENV']| | development'
环境['NODE_ENV']| |='development'
需要“路径名”
ENV['BUNDLE_GEMFILE']||=File.expand_path('../../GEMFILE',
路径名.new(_文件\u_).realpath)
需要“捆绑机/设置”
需要“webpacker”
需要“webpack/webpack\u runner”
APP_ROOT=File.expand_path(“..”,uu dir_uu)
目录chdir(APP_ROOT)do
Webpacker::WebpackRunner.run(ARGV)
结束
这是我的webpacker开发服务器文件

#/usr/bin/env ruby
ENV['RAILS_ENV']| |=ENV['RACK_ENV']| | development'
环境['NODE_ENV']| |='development'
需要“路径名”
ENV['BUNDLE_GEMFILE']||=File.expand_path('../../GEMFILE',
路径名.new(_文件\u_).realpath)
需要“捆绑机/设置”
需要“webpacker”
需要“webpacker/dev_server_runner”
APP_ROOT=File.expand_path(“..”,uu dir_uu)
目录chdir(APP_ROOT)do
Webpacker::DevServerRunner.run(ARGV)
结束

我不确定我是否完全理解您的问题,但我遇到了一个问题,即默认的rails网页包服务器重建每个
.js(x)
文件时会发生更改,并且在开发过程中花费了很长时间。我用
gem-foreman

  • 安装
  • 在项目根目录中创建
    Procfile.dev
  • 我的网页包开发服务器
  • #/usr/bin/env ruby
    ENV[“RAILS_ENV”]| |=ENV[“RACK_ENV”]| |“development”
    ENV[“NODE_ENV”]| |=ENV[“NODE_ENV”]| |“development”
    需要“路径名”
    ENV[“BUNDLE_GEMFILE”]| |=File.expand_path(“../../GEMFILE”,
    路径名.new(_文件\u_).realpath)
    需要“rubygems”
    需要“捆绑机/设置”
    需要“webpacker”
    需要“webpacker/dev_server_runner”
    Webpacker::DevServerRunner.run(ARGV)
    
  • 和工头一起管理项目
    foreman start-f Procfile.dev-p 3000
  • 在此之后-webpack不会构建每次更改,并且重新加载代码更改所需的时间更少

    您还可以更新您的
    webpacker.yml

    # Note: You must restart bin/webpack-dev-server for changes to take effect
    
    default: &default
      source_path: app/javascript
      source_entry_path: 'packs'
      public_output_path: 'packs'
      cache_path: tmp/cache/webpacker
    
      # Additional paths webpack should lookup modules
      resolved_paths: ['app/javascript/src']
    
      # Reload manifest.json on all requests so we reload latest compiled packs
      cache_manifest: false
    
      extensions:
        - .jsx
        - .js
        - .sass
        - .scss
        - .css
        - .module.sass
        - .module.scss
        - .module.css
        - .png
        - .svg
        - .gif
        - .jpeg
        - .jpg
    
    development:
      <<: *default
      compile: true
    
      # Reference: https://webpack.js.org/configuration/dev-server/
      dev_server:
        https: false
        host: localhost
        port: 3035
        public: localhost:3035
        hmr: false
        # Inline should be set to true if using HMR
        inline: true
        overlay: true
        compress: true
        disable_host_check: true
        use_local_ip: false
        quiet: false
        headers:
          'Access-Control-Allow-Origin': '*'
        watch_options:
          ignored: /node_modules/
    
    
    production:
      <<: *default
      public_path: <%= ENV['ACTION_CONTROLLER_ASSET_HOST'] %>
    
      # Production depends on precompilation of packs prior to booting for performance.
      compile: false
    
      # Cache manifest.json for performance
      cache_manifest: true
    
    
    #注意:要使更改生效,必须重新启动bin/webpack dev服务器
    默认值:&默认值
    源路径:app/javascript
    源\条目\路径:“包”
    公共_输出_路径:“包”
    缓存路径:tmp/cache/webpacker
    #Web包应提供其他路径查找模块
    已解析的路径:['app/javascript/src']
    #在所有请求上重新加载manifest.json,以便重新加载最新编译的包
    缓存清单:false
    扩展:
    -.jsx
    -.js
    -萨斯先生
    -.scss
    -.css
    -.module.sass
    -.module.scss
    -.module.css
    -.png
    -.svg
    -.gif
    -.jpeg
    -jpg先生
    发展:
    
    # Note: You must restart bin/webpack-dev-server for changes to take effect
    
    default: &default
      source_path: app/javascript
      source_entry_path: 'packs'
      public_output_path: 'packs'
      cache_path: tmp/cache/webpacker
    
      # Additional paths webpack should lookup modules
      resolved_paths: ['app/javascript/src']
    
      # Reload manifest.json on all requests so we reload latest compiled packs
      cache_manifest: false
    
      extensions:
        - .jsx
        - .js
        - .sass
        - .scss
        - .css
        - .module.sass
        - .module.scss
        - .module.css
        - .png
        - .svg
        - .gif
        - .jpeg
        - .jpg
    
    development:
      <<: *default
      compile: true
    
      # Reference: https://webpack.js.org/configuration/dev-server/
      dev_server:
        https: false
        host: localhost
        port: 3035
        public: localhost:3035
        hmr: false
        # Inline should be set to true if using HMR
        inline: true
        overlay: true
        compress: true
        disable_host_check: true
        use_local_ip: false
        quiet: false
        headers:
          'Access-Control-Allow-Origin': '*'
        watch_options:
          ignored: /node_modules/
    
    
    production:
      <<: *default
      public_path: <%= ENV['ACTION_CONTROLLER_ASSET_HOST'] %>
    
      # Production depends on precompilation of packs prior to booting for performance.
      compile: false
    
      # Cache manifest.json for performance
      cache_manifest: true