diff --git a/packages/component/.size-snapshot.json b/packages/component/.size-snapshot.json index 7a595a14..dd155c0d 100644 --- a/packages/component/.size-snapshot.json +++ b/packages/component/.size-snapshot.json @@ -1,20 +1,20 @@ { "dist/loadable.cjs.js": { - "bundled": 14563, - "minified": 7172, - "gzipped": 2534 + "bundled": 16387, + "minified": 7324, + "gzipped": 2574 }, "dist/loadable.esm.js": { - "bundled": 14184, - "minified": 6868, - "gzipped": 2467, + "bundled": 16008, + "minified": 7020, + "gzipped": 2506, "treeshaked": { "rollup": { "code": 276, "import_statements": 276 }, "webpack": { - "code": 5744 + "code": 5896 } } } diff --git a/packages/server/src/ChunkExtractor.js b/packages/server/src/ChunkExtractor.js index 64aa6b0b..04110c21 100644 --- a/packages/server/src/ChunkExtractor.js +++ b/packages/server/src/ChunkExtractor.js @@ -201,17 +201,20 @@ class ChunkExtractor { } createChunkAsset({ filename, chunk, type, linkType }) { + const resolvedFilename = + typeof filename === 'object' && filename.name ? filename.name : filename + return { - filename, + filename: resolvedFilename, scriptType: extensionToScriptType( path - .extname(filename) + .extname(resolvedFilename) .split('?')[0] .toLowerCase(), ), chunk, - url: this.resolvePublicUrl(filename), - path: path.join(this.outputPath, filename), + url: this.resolvePublicUrl(resolvedFilename), + path: path.join(this.outputPath, resolvedFilename), type, linkType, } diff --git a/packages/webpack-plugin/src/index.js b/packages/webpack-plugin/src/index.js index 1a3d8445..e1bca431 100644 --- a/packages/webpack-plugin/src/index.js +++ b/packages/webpack-plugin/src/index.js @@ -72,8 +72,14 @@ class LoadablePlugin { apply(compiler) { this.compiler = compiler - // Add a custom output.jsonpFunction: __LOADABLE_LOADED_CHUNKS__ - compiler.options.output.jsonpFunction = '__LOADABLE_LOADED_CHUNKS__' + // Check if webpack version 4 or 5 + if ('jsonpFunction' in compiler.options.output) { + // Add a custom output.jsonpFunction: __LOADABLE_LOADED_CHUNKS__ + compiler.options.output.jsonpFunction = '__LOADABLE_LOADED_CHUNKS__' + } else { + // Add a custom output.chunkLoadingGlobal: __LOADABLE_LOADED_CHUNKS__ + compiler.options.output.chunkLoadingGlobal = '__LOADABLE_LOADED_CHUNKS__' + } if (this.opts.outputAsset || this.opts.writeToDisk) { compiler.hooks.emit.tapAsync('@loadable/webpack-plugin', this.handleEmit) diff --git a/yarn.lock b/yarn.lock index d32ba8b7..3b378e27 100644 --- a/yarn.lock +++ b/yarn.lock @@ -185,11 +185,6 @@ resolved "https://registry.yarnpkg.com/@babel/helper-plugin-utils/-/helper-plugin-utils-7.0.0.tgz#bbb3fbee98661c569034237cc03967ba99b4f250" integrity sha512-CYAOUCARwExnEixLdB6sDm2dIJ/YgEAKDM1MOeMeZu9Ld/bDgVo8aiWrXwcY7OBh+1Ea2uUcVRcxKk0GJvW7QA== -"@babel/helper-plugin-utils@^7.8.3": - version "7.8.3" - resolved "https://registry.yarnpkg.com/@babel/helper-plugin-utils/-/helper-plugin-utils-7.8.3.tgz#9ea293be19babc0f52ff8ca88b34c3611b208670" - integrity sha512-j+fq49Xds2smCUNYmEHF9kGNkhbet6yVIBp4e6oeQpH1RUs/Ir06xUKzDjDkGcaaokPiTNs2JBWHjaE4csUkZQ== - "@babel/helper-regex@^7.0.0", "@babel/helper-regex@^7.4.4": version "7.5.5" resolved "https://registry.yarnpkg.com/@babel/helper-regex/-/helper-regex-7.5.5.tgz#0aa6824f7100a2e0e89c1527c23936c152cab351" @@ -305,14 +300,6 @@ "@babel/helper-plugin-utils" "^7.0.0" "@babel/plugin-syntax-dynamic-import" "^7.7.4" -"@babel/plugin-proposal-function-bind@^7.8.3": - version "7.8.3" - resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-function-bind/-/plugin-proposal-function-bind-7.8.3.tgz#e34a1e984771b84b6e5322745edeadca7e500ced" - integrity sha512-6q7VAHJQa9x4P6Lm6h6KHoJUEhx2r1buFKseHICe0ogb1LWxducO4tsQp3hd/7BVBo485YBsn6tJnpuwWm/9cA== - dependencies: - "@babel/helper-plugin-utils" "^7.8.3" - "@babel/plugin-syntax-function-bind" "^7.8.3" - "@babel/plugin-proposal-json-strings@^7.7.4": version "7.7.4" resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-json-strings/-/plugin-proposal-json-strings-7.7.4.tgz#7700a6bfda771d8dc81973249eac416c6b4c697d" @@ -366,13 +353,6 @@ dependencies: "@babel/helper-plugin-utils" "^7.0.0" -"@babel/plugin-syntax-function-bind@^7.8.3": - version "7.8.3" - resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-function-bind/-/plugin-syntax-function-bind-7.8.3.tgz#17d722cd8efc9bb9cf8bc59327f2b26295b352f7" - integrity sha512-gEYag4Q3CfqlQcJQQw/KSWdV2husGOnIsOsRlyzkoaNqj2V/V/CSdSJDCGSl67oJ1bdIYP6TjORWPH561dSJpA== - dependencies: - "@babel/helper-plugin-utils" "^7.8.3" - "@babel/plugin-syntax-json-strings@^7.7.4": version "7.7.4" resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-json-strings/-/plugin-syntax-json-strings-7.7.4.tgz#86e63f7d2e22f9e27129ac4e83ea989a382e86cc"