-
Hello, I am trying to migrate my setup from sprockets to webpack using shakapacker.
How could I do the same in my entry point file?
It doesn't work, because in my view I get errors in the JS console saying some JS objects are missing (they are defined in the files I want to include). |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
In general, the code you've attached would be the way I would expect to work to pull in all the files under a tree. Played around with this locally and all operating as expected If you're getting view errors, I do wonder if something is trying to reference vars in the script before they are defined. Can you give some example of code that is referencing something you load from the included files or any reproduction case? |
Beta Was this translation helpful? Give feedback.
OK, I think I know why this is. Imports are hoisted to the top whilst requires are not.
I've tried a small repro like:
And verified
src/reference_test
is loaded and evaluated before theimportAll
To fix this and maintain the order, you can try changing your import to require like:
This should retain execution order and mean the toolbox.js file will only be loaded and executed after that
importAll