diff --git a/build/chunk-preload-plugin.js b/build/chunk-preload-plugin.js deleted file mode 100644 index 0beb321b..00000000 --- a/build/chunk-preload-plugin.js +++ /dev/null @@ -1,72 +0,0 @@ -/** Copyright (c) 2018 Uber Technologies, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @flow - */ - -/* eslint-env node */ - -/** - * Webpack plugin for being able to mark async chunks as being already preloaded - * This is meant for the client and ensures that webpack only requests for chunks - * once. This is necessary because we automatically inline scripts for async chunks - * that are used during the server side render. We use Object.defineProperty to make - * the values lazy so `new Promise` is not executed until the promise polyfill is loaded. - */ - -const Template = require('webpack/lib/Template'); - -class ChunkPreloadPlugin { - apply(compiler /*: any */) { - compiler.hooks.compilation.tap('ChunkPreloadPlugin', function(compilation) { - compilation.mainTemplate.hooks.localVars.tap( - 'ChunkPreloadPlugin', - function(source) { - var buf = [source]; - buf.push(''); - buf.push('// chunk preloading'); - buf.push( - ` - if (window.__PRELOADED_CHUNKS__) { - window.__PRELOADED_CHUNKS__.forEach(function(chunkId) { - var result; - Object.defineProperty(installedChunks, chunkId, { - get: function() { - if (result) { - return result; - } - var promise = new Promise(function(resolve, reject) { - result = [resolve, reject]; - }); - result[2] = promise; - return result; - } - }); - }); - } - - var rejectChunkPreload = function(chunkId) { - var chunk = installedChunks[chunkId]; - if(chunk !== 0) { - if(chunk) chunk[1](new Error('Loading chunk ' + chunkId + ' failed.')); - installedChunks[chunkId] = undefined; - } - } - - window.__HANDLE_ERROR = rejectChunkPreload; - - if (window.__UNHANDLED_ERRORS__) { - window.__UNHANDLED_ERRORS__.forEach(rejectChunkPreload); - } - ` - ); - return Template.asString(buf); - } - ); - }); - } -} - -module.exports = ChunkPreloadPlugin; diff --git a/build/compiler.js b/build/compiler.js index d26fe44e..368f68ce 100644 --- a/build/compiler.js +++ b/build/compiler.js @@ -27,7 +27,6 @@ const resolveFrom = require('resolve-from'); const AssetsManifestPlugin = require('@nadiia/file-loader') .assetsManifestPlugin; const ClientSourceMapPlugin = require('./client-source-map-plugin'); -const ChunkPreloadPlugin = require('./chunk-preload-plugin'); const ChunkModuleManifestPlugin = require('./chunk-module-manifest-plugin'); const chunkModuleManifest = require('./chunk-module-manifest'); const InstrumentedImportDependencyTemplatePlugin = require('./instrumented-import-dependency-template-plugin'); @@ -448,9 +447,6 @@ function getConfig({target, env, dir, watch, cover}) { env === 'production' && target === 'web' && new webpack.HashedModuleIdsPlugin(), - target === 'web' && env !== 'test' && new ChunkPreloadPlugin(), - // TODO(#11): What do we do for client-side error reporting in the service worker? - // Do we add in reporting code to the sw? Should we map stack traces on the server? target === 'web' && new ClientSourceMapPlugin(), target === 'web' && new SyncChunkIdsPlugin(), target === 'web' && diff --git a/test/cli/build.js b/test/cli/build.js index 53609a54..411d1f03 100644 --- a/test/cli/build.js +++ b/test/cli/build.js @@ -205,15 +205,15 @@ test('`fusion build` app with dynamic imports integration', async t => { ); t.equal( await page.$$eval('script', els => els.length), - 6, - 'should be 6 scripts' + 5, + 'should be 5 scripts' ); await page.click('#split-route-link'); t.equal( await page.$$eval('script', els => els.length), - 7, - 'should be 7 scripts after dynamic loading' + 6, + 'should be 6 scripts after dynamic loading' ); t.ok(