Last active
October 7, 2016 17:31
-
-
Save ryankshaw/0270d708bcabbcd68edc89d2562af98d to your computer and use it in GitHub Desktop.
how would I accomplish this same thing in webpack?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// if someone requires 'timezone', I want it to get this file | |
// and then based on some info in a global variable 'window.ENV' | |
// at runtime fetch a json file with a bunch of data specific to | |
// that timezone and then export the 'timezone' object, with | |
// that zone's data preloaded. in requireJS, I had a loader that | |
// looked something like this | |
// in timezone.js | |
define(['timezone_core'], function(timezone) { | |
//see: http://requirejs.org/docs/plugins.html#apiload for the specifics of how this api works | |
load: function (name, require, onload, config) { | |
var usersTimezone = window.ENV.timezone | |
// fetch the data for the user's timezone async | |
require(['timezone_data/' + usersTimezone], function (dataForUsersTimezone) { | |
timezone.preloadWith(dataForUsersTimezone) | |
// this is what we actually export to anyone that 'require's 'timezone'. | |
// it will be the timezone object preloaded with the user's timezone data | |
onload(timezone); | |
}); | |
} | |
}) | |
// when built, 'timezone_core' and this 'timezone' loader get concatenated into the | |
// main bundle, but it would make a seperate request to 'timezone_data/America_Denver' | |
// and wait for that to come back before providing the 'timezone' module to any | |
// other module that 'require's it. Note: I don't want all of the data for all | |
// the timezones be concatenated into the bundle, that would make it huge. I just | |
// want it to to a request for the timezone it needs | |
// how would I do the same thing in webpack? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment