简体   繁体   中英

Importing other function in Stimulus controller

In a Stimulus controller in Rails 7 I am importing functions from another js file in my /javascript directory

import * as myHelpers from "../helpers/my_helpers.js";

This works fine in development, but in production I get a 404 for the included file as it is being looked for at /assets/helpers/my_helpers.js . Do the javascript controllers move in production? Is there a way to reference this file?

I got this working by using the import map config/importmap.rb:

pin_all_from "app/javascript/helpers", under: "helpers"

And then in the controller

import * as myHelpers from "helpers/my_helpers";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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