Search code examples
ruby-on-railswebpacker

webpacker syntax for imports


A rails assets/javascript directory has the following sub-directories:
channels
packs
src
I have the following in an application.js file

import("../src/foundation-datepicker")
import("../src/user_dob")

But these files are not importing as Webpacker can't find and therefore not create the manifest.

What is the proper syntax to import these?


Solution

  • in webpacker.yml add your assets/javascript directory to additional_paths so that webpack will lookup modules also in that dicrectory

    # config/webpacker.yml
    additional_paths: ['app/assets/javascript']
    
    # app/javascript/packs/application.js
    import("src/foundation-datepicker")
    import("src/user_dob")