@@ -92,6 +92,22 @@ var parseBundlePlugin = function(data, base_dir) {
9292 ] ,
9393 } ;
9494
95+ // Calculate these paths here, so that we can export __publicPath as a variable in the webpack define plugin
96+ var publicPath , outputPath ;
97+
98+ if ( process . env . DEV_SERVER ) {
99+ var devServerConfig = require ( './webpackdevserverconfig' ) ;
100+ // If running webpack dev server point to that endpoint.
101+ publicPath = devServerConfig . publicPath ;
102+ // Set output path to base dir, as no files will be written - all built files are cached in memory.
103+ outputPath = devServerConfig . basePath
104+ ? path . resolve ( path . join ( base_dir , devServerConfig . basePath ) )
105+ : path . resolve ( base_dir ) ;
106+ } else {
107+ publicPath = path . join ( '/' , data . static_url_root , data . name , '/' ) ;
108+ outputPath = path . join ( data . static_dir , data . name ) ;
109+ }
110+
95111 bundle . plugins = bundle . plugins . concat ( [
96112 new ExtractTextPlugin ( '[name]' + data . version + '.css' ) ,
97113 new WebpackRTLPlugin ( ) ,
@@ -110,27 +126,14 @@ var parseBundlePlugin = function(data, base_dir) {
110126 __events : JSON . stringify ( data . events || { } ) ,
111127 __once : JSON . stringify ( data . once || { } ) ,
112128 __version : JSON . stringify ( data . version ) ,
129+ // This is necessary to allow modules that use service workers to fetch their service worker code
130+ __publicPath : JSON . stringify ( publicPath ) ,
113131 } ) ,
114132 new extract$trs ( data . locale_data_folder , data . name ) ,
115133 ] ) ;
116134
117135 bundle = merge . smart ( bundle , local_config ) ;
118136
119- var publicPath , outputPath ;
120-
121- if ( process . env . DEV_SERVER ) {
122- var devServerConfig = require ( './webpackdevserverconfig' ) ;
123- // If running webpack dev server point to that endpoint.
124- publicPath = devServerConfig . publicPath ;
125- // Set output path to base dir, as no files will be written - all built files are cached in memory.
126- outputPath = devServerConfig . basePath
127- ? path . resolve ( path . join ( base_dir , devServerConfig . basePath ) )
128- : path . resolve ( base_dir ) ;
129- } else {
130- publicPath = path . join ( '/' , data . static_url_root , data . name , '/' ) ;
131- outputPath = path . join ( data . static_dir , data . name ) ;
132- }
133-
134137 bundle . core_name = data . core_name ;
135138 bundle . name = data . name ;
136139 bundle . context = base_dir ;
0 commit comments