buildkite / frontend

🌏 The front-end application code for https://buildkite.com
MIT License
137 stars 27 forks source link

Use standard “require” naming for our require shim #783

Closed ticky closed 5 years ago

keithpitt commented 5 years ago

@ticky I wonder if we should turn this thing into a big loop?

const imports = [
"app/foo/bar"
]

window["require"];

for x in imports {
 window["require"].modules[x] = require(x);
}

Would Webpack figure that out?

Was wondering if we can have consistent naming in the require list here, and inside the app. So you require "app/components/shared" in both side (instead of the "./compoentns" syntax here.

(note: what I said makes little difference to anything)

keithpitt commented 5 years ago

Also: question!

Will window["require"] collide with using require in Webpack land?

ticky commented 5 years ago

I believe Webpack would import every possible import if we did it that way, unfortunately! I’d rather not rock the boat too hard as the next few steps of this will remove the existence of this shim altogether!

window["require"] won’t ever conflict because the Webpack require function gets changed to __webpack_require__ in dev, and further to a single-character name in production builds. It also can be referenced specifically (though I don’t know why we would) from Webpack-powered code by referencing it specifically as window["require”].