Skip to content

Import multiple files in webpack entry point #468

Closed Answered by tomdracz
afdev82 asked this question in Q&A
Discussion options

You must be logged in to vote

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:

const importAll = (r) => r.keys().forEach(r);
importAll(require.context('../nested/', true, /\.js$/));
import '../src/reference_test'

And verified src/reference_test is loaded and evaluated before the importAll

To fix this and maintain the order, you can try changing your import to require like:

function importAll(r) {
  r.keys().forEach(r);
}

importAll(require.context('./configurator/core/auto/', true, /\.js$/));

require('./configurator/core/toolbox.js')

This should retain execution order and mean the toolbox.js file will only be loaded and executed after that importAll

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@afdev82
Comment options

@tomdracz
Comment options

Answer selected by afdev82
@afdev82
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants