I am trying to understand how to switch my project to webpack.
I originally set things up based on the guide here: https://phoenixframework.org/blog/static-assets
I understand that “require()” is in fact part of Brunch’s “bootstrapper” code, but what I haven’t figured out is what the equivalent is in Webpack.
require is part of the CommonJS module standard used by Node.js and webpack has no problem dealing with it.
The sample JS files that are part of the Phoenix 1.4 distribution use the more recent ES2015 module standard which is the currently recommended standard for use with client side code (which requires the inclusion of babel-loader in the webpack configuration).
So you should be able to get your current JS code to work with webpack - in fact for the time being the
webpack.config.js is easier to maintain in the CommonJS style.
However eventually you should familiarize yourself with ES2015 modules and update your client side code (