Webpacker: Compile files without running dev server

Created on 24 Jan 2018  路  6Comments  路  Source: rails/webpacker

There is a paragraph in the development section of the documentation that makes it seem like compilation should happen without having to run any other processes than your rails server:

In development, Webpacker compiles on demand rather than upfront by default. This happens when you refer to any of the pack assets using the Webpacker helper methods. That means you don't have to run any separate process. Compilation errors are logged to the standard Rails log.

I can't seem to figure out how to make this happen? Everything seems to work fine if I run the watcher or the dev server, but it would be nice for other developers that are maybe working on backend stuff to not have to run the webpack dev server all the time, or even be aware of such concerns.

Most helpful comment

@1campbellj Is this still an issue? Please could you clear cache - bundle exec rails tmp:cache:clear

All 6 comments

@1campbellj Is compile: true flag set in webpacker.yml under development env? Also, make sure webpack dev server isn't running.

I just ran into this as well with a brand new Rails app and Webpacker install. Without running webpack or webpack-dev-server, javascript_pack_tag was raising Webpacker::Manifest::MissingEntryError. After running webpack, the action rendered without error, but application.js encountered a 404.

My issue was a separate webpack-dev-server running for a different project. Once I killed that process, compiling on demand worked as expected. I think there's a problem with how Webpacker determines if the dev server is running, but I haven't been able to dig deeper than that.

@adamlogic Thanks, that makes sense - an easy fix would be to change port in config/webpacker.yml if you have 2 or more projects using webpacker.

@gauravtiwari I inserted my webpacker.yml below. Compile is set to true and I made sure the dev server was off, and I still get 404 errors because it doesn't seem to be compiling without the dev server. I can confirm no other node processes are running either so I don't think it's the same issue adamlogic had.

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
  # ['app/assets', 'engine/foo/app/assets']
  resolved_paths: []

  # Reload manifest.json on all requests so we reload latest compiled packs
  cache_manifest: false

  extensions:
    - .coffee
    - .erb
    - .js
    - .jsx
    - .ts
    - .vue
    - .sass
    - .scss
    - .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: true
    # 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/

@1campbellj Is this still an issue? Please could you clear cache - bundle exec rails tmp:cache:clear

Not an issue for me anymore, thanks for following up. I'm actually not sure what fixed it for me.

Was this page helpful?
0 / 5 - 0 ratings