diff --git a/lib/plugin.js b/lib/plugin.js index 047f2ba..d21f96b 100644 --- a/lib/plugin.js +++ b/lib/plugin.js @@ -40,10 +40,12 @@ ManifestPlugin.prototype.apply = function(compiler) { var outputName = path.relative(outputFolder, outputFile); var moduleAsset = function (module, file) { - moduleAssets[file] = path.join( - path.dirname(file), - path.basename(module.userRequest) - ); + if (module.userRequest) { + moduleAssets[file] = path.join( + path.dirname(file), + path.basename(module.userRequest) + ); + } }; var emit = function(compilation, compileCallback) { diff --git a/package.json b/package.json index 4f4de87..f73b534 100644 --- a/package.json +++ b/package.json @@ -22,8 +22,10 @@ "file-loader": "^1.1.11", "jest": "^22.4.3", "memory-fs": "^0.2.0", + "react": "^16.3.2", "rimraf": "^2.6.1", "style-loader": "^0.8.3", + "svgr": "^1.9.2", "webpack": "^3.5.2" }, "files": [ diff --git a/spec/plugin.integration.spec.js b/spec/plugin.integration.spec.js index 4a62a78..5a20f5a 100644 --- a/spec/plugin.integration.spec.js +++ b/spec/plugin.integration.spec.js @@ -436,3 +436,48 @@ describe('ManifestPlugin with memory-fs', function() { }); }); }); + +describe('scoped hoisting', function() { + beforeAll(function () { + fse.outputFileSync(path.join(__dirname, 'output/scoped-hoisting/index.js'), 'import { ReactComponent } from "./logo.svg";'); + fse.outputFileSync(path.join(__dirname, 'output/scoped-hoisting/logo.svg'), ''); + }); + + it('outputs a manifest', function(done) { + let plugins; + if (webpack.optimize.ModuleConcatenationPlugin) { + // ModuleConcatenationPlugin works with webpack 3, 4. + plugins = [ + new webpack.optimize.ModuleConcatenationPlugin(), + new ManifestPlugin(), + ]; + } else { + plugins = [ + new ManifestPlugin(), + ]; + } + compiler = webpackCompile({ + context: __dirname, + entry: './output/scoped-hoisting/index.js', + module: { + rules: [ + { + test: /\.svg$/, + use: ['svgr/webpack', 'file-loader'] + }, + ], + }, + output: { + filename: '[name].[hash].js', + path: path.join(__dirname, 'output/scoped-hoisting') + }, + plugins, + }, {}, function(stats) { + var manifest = JSON.parse(fse.readFileSync(path.join(__dirname, 'output/scoped-hoisting/manifest.json'))) + + expect(manifest).toBeDefined(); + expect(manifest['main.js']).toEqual('main.'+ stats.hash +'.js'); + return done(); + }); + }); +});