@@ -90,6 +90,22 @@ var parseBundlePlugin = function(data, base_dir) {
9090 ] ,
9191 } ;
9292
93+ // Calculate these paths here, so that we can export __publicPath as a variable in the webpack define plugin
94+ var publicPath , outputPath ;
95+
96+ if ( process . env . DEV_SERVER ) {
97+ var devServerConfig = require ( './webpackdevserverconfig' ) ;
98+ // If running webpack dev server point to that endpoint.
99+ publicPath = devServerConfig . publicPath ;
100+ // Set output path to base dir, as no files will be written - all built files are cached in memory.
101+ outputPath = devServerConfig . basePath
102+ ? path . resolve ( path . join ( base_dir , devServerConfig . basePath ) )
103+ : path . resolve ( base_dir ) ;
104+ } else {
105+ publicPath = path . join ( '/' , data . static_url_root , data . name , '/' ) ;
106+ outputPath = path . join ( data . static_dir , data . name ) ;
107+ }
108+
93109 bundle . plugins = bundle . plugins . concat ( [
94110 // BundleTracker creates stats about our built files which we can then pass to Django to allow our template
95111 // tags to load the correct frontend files.
@@ -106,27 +122,14 @@ var parseBundlePlugin = function(data, base_dir) {
106122 __events : JSON . stringify ( data . events || { } ) ,
107123 __once : JSON . stringify ( data . once || { } ) ,
108124 __version : JSON . stringify ( data . version ) ,
125+ // This is necessary to allow modules that use service workers to fetch their service worker code
126+ __publicPath : JSON . stringify ( publicPath ) ,
109127 } ) ,
110128 new extract$trs ( data . locale_data_folder , data . name ) ,
111129 ] ) ;
112130
113131 bundle = merge . smart ( bundle , local_config ) ;
114132
115- var publicPath , outputPath ;
116-
117- if ( process . env . DEV_SERVER ) {
118- var devServerConfig = require ( './webpackdevserverconfig' ) ;
119- // If running webpack dev server point to that endpoint.
120- publicPath = devServerConfig . publicPath ;
121- // Set output path to base dir, as no files will be written - all built files are cached in memory.
122- outputPath = devServerConfig . basePath
123- ? path . resolve ( path . join ( base_dir , devServerConfig . basePath ) )
124- : path . resolve ( base_dir ) ;
125- } else {
126- publicPath = path . join ( '/' , data . static_url_root , data . name , '/' ) ;
127- outputPath = path . join ( data . static_dir , data . name ) ;
128- }
129-
130133 bundle . core_name = data . core_name ;
131134 bundle . name = data . name ;
132135 bundle . context = base_dir ;
0 commit comments