@@ -2,6 +2,7 @@ var RawSource = require('webpack-sources/lib/RawSource');
22var evaluate = require ( 'eval' ) ;
33var path = require ( 'path' ) ;
44var cheerio = require ( 'cheerio' ) ;
5+ var JSDOM = require ( 'jsdom' ) . JSDOM ;
56var url = require ( 'url' ) ;
67var Promise = require ( 'bluebird' ) ;
78var vm = require ( 'vm' ) ;
@@ -127,31 +128,27 @@ function merge (a, b) {
127128 * Function to handle commonschunk plugin. Currently only supports a manifest file and single external
128129 * library file name vendor.
129130 */
130- var loadChunkAssetsToScope = function ( scope , compilation , webpackStatsJson ) {
131- var chunkNames = Object . keys ( webpackStatsJson . assetsByChunkName )
132- var chunkValues = chunkNames . map ( function ( chunk ) {
133- return findAsset ( chunk , compilation , webpackStatsJson ) ;
134- } ) ;
131+ var loadChunkAssetsToScope = function ( globals , compilation , webpackStatsJson ) {
132+ var dom = new JSDOM ( '' , { runScripts : 'outside-only' } ) ;
133+ var chunkNames = Object . keys ( webpackStatsJson . assetsByChunkName ) ;
135134
136- if ( ! scope ) {
137- scope = { } ;
135+ // CommonChunksPlugin will place webpackJsonP manifest loading in last bundle
136+ if ( chunkNames [ chunkNames . length - 1 ] === 'manifest' ) {
137+ chunkNames = [ 'manifest' ] . concat ( chunkNames . slice ( 0 , - 1 ) ) ;
138138 }
139139
140- if ( ! scope . window ) {
141- scope . window = { } ;
142- }
140+ var chunkValues = chunkNames . map ( function ( chunk ) {
141+ return findAsset ( chunk , compilation , webpackStatsJson ) ;
142+ } ) ;
143143
144- var sandbox = { } ;
145- merge ( sandbox , scope ) ;
144+ merge ( dom . window , globals ) ;
146145
147- // CommonChunksPlugin will place webpackJsonP manifest loading in last bundle
148- chunkValues . reverse ( ) . map ( function ( chunk ) {
146+ chunkValues . map ( function ( chunk ) {
149147 var script = new vm . Script ( chunk . source ( ) ) ;
150- script . runInNewContext ( sandbox , { } ) ;
151- merge ( sandbox , sandbox . window ) ;
148+ dom . runVMScript ( script ) ;
152149 } ) ;
153150
154- return sandbox ;
151+ return dom . window ;
155152}
156153
157154var findAsset = function ( src , compilation , webpackStatsJson ) {
0 commit comments