diff --git a/lib/AmdMainTemplatePlugin.js b/lib/AmdMainTemplatePlugin.js index 2093edac60a..35c8bc0a655 100644 --- a/lib/AmdMainTemplatePlugin.js +++ b/lib/AmdMainTemplatePlugin.js @@ -79,7 +79,9 @@ class AmdMainTemplatePlugin { mainTemplate.hooks.hash.tap("AmdMainTemplatePlugin", hash => { hash.update("exports amd"); - hash.update(this.name); + if (this.name) { + hash.update(this.name); + } }); } } diff --git a/test/configCases/target/amd-named/index.js b/test/configCases/target/amd-named/index.js new file mode 100644 index 00000000000..0d9cc474b4f --- /dev/null +++ b/test/configCases/target/amd-named/index.js @@ -0,0 +1,10 @@ +it("should run", function() { + +}); + +it("should name define", function() { + var fs = require("fs"); + var source = fs.readFileSync(__filename, "utf-8"); + + expect(source).toMatch("define(\"NamedLibrary\","); +}); diff --git a/test/configCases/target/amd-named/webpack.config.js b/test/configCases/target/amd-named/webpack.config.js new file mode 100644 index 00000000000..f80f8f3a0d2 --- /dev/null +++ b/test/configCases/target/amd-named/webpack.config.js @@ -0,0 +1,17 @@ +const webpack = require("../../../../"); +module.exports = { + output: { + library: "NamedLibrary", + libraryTarget: "amd" + }, + node: { + __dirname: false, + __filename: false + }, + plugins: [ + new webpack.BannerPlugin({ + raw: true, + banner: "function define(name, deps, fn) { fn(); }\n" + }) + ] +}; diff --git a/test/configCases/target/amd-unnamed/index.js b/test/configCases/target/amd-unnamed/index.js new file mode 100644 index 00000000000..85d11d914b2 --- /dev/null +++ b/test/configCases/target/amd-unnamed/index.js @@ -0,0 +1,10 @@ +it("should run", function() { + +}); + +it("should name define", function() { + var fs = require("fs"); + var source = fs.readFileSync(__filename, "utf-8"); + + expect(source).toMatch("define(function("); +}); diff --git a/test/configCases/target/amd-unnamed/webpack.config.js b/test/configCases/target/amd-unnamed/webpack.config.js new file mode 100644 index 00000000000..494051b75af --- /dev/null +++ b/test/configCases/target/amd-unnamed/webpack.config.js @@ -0,0 +1,16 @@ +const webpack = require("../../../../"); +module.exports = { + output: { + libraryTarget: "amd" + }, + node: { + __dirname: false, + __filename: false + }, + plugins: [ + new webpack.BannerPlugin({ + raw: true, + banner: "function define(deps, fn) { fn(); }\n" + }) + ] +};