diff --git a/declarations/plugins/DllPlugin.d.ts b/declarations/plugins/DllPlugin.d.ts index f7264c2dab3..addbce540f1 100644 --- a/declarations/plugins/DllPlugin.d.ts +++ b/declarations/plugins/DllPlugin.d.ts @@ -13,6 +13,10 @@ export interface DllPluginOptions { * If true, only entry points will be exposed */ entryOnly?: boolean; + /** + * If true, manifest json file (output) will be formatted + */ + format?: boolean; /** * Name of the exposed dll function (external name, use value of 'output.library') */ diff --git a/lib/LibManifestPlugin.js b/lib/LibManifestPlugin.js index 54dbf10a0fa..05e98b047cc 100644 --- a/lib/LibManifestPlugin.js +++ b/lib/LibManifestPlugin.js @@ -67,7 +67,11 @@ class LibManifestPlugin { return obj; }, Object.create(null)) }; - const content = Buffer.from(JSON.stringify(manifest), "utf8"); + // Apply formatting to content if format flag is true; + const manifestContent = this.options.format + ? JSON.stringify(manifest, null, 2) + : JSON.stringify(manifest); + const content = Buffer.from(manifestContent, "utf8"); compiler.outputFileSystem.mkdirp(path.dirname(targetPath), err => { if (err) return callback(err); compiler.outputFileSystem.writeFile( diff --git a/schemas/plugins/DllPlugin.json b/schemas/plugins/DllPlugin.json index 8d9961e8974..18d7dee431e 100644 --- a/schemas/plugins/DllPlugin.json +++ b/schemas/plugins/DllPlugin.json @@ -12,6 +12,10 @@ "description": "If true, only entry points will be exposed", "type": "boolean" }, + "format": { + "description": "If true, manifest json file (output) will be formatted", + "type": "boolean" + }, "name": { "description": "Name of the exposed dll function (external name, use value of 'output.library')", "type": "string", diff --git a/test/configCases/dll-plugin-format/0-create-dll/dep.js b/test/configCases/dll-plugin-format/0-create-dll/dep.js new file mode 100644 index 00000000000..e7134e7006d --- /dev/null +++ b/test/configCases/dll-plugin-format/0-create-dll/dep.js @@ -0,0 +1 @@ +module.exports = "foo"; diff --git a/test/configCases/dll-plugin-format/0-create-dll/index.js b/test/configCases/dll-plugin-format/0-create-dll/index.js new file mode 100644 index 00000000000..59ef4a4cd38 --- /dev/null +++ b/test/configCases/dll-plugin-format/0-create-dll/index.js @@ -0,0 +1,4 @@ +export { add } from "./utility"; +export default "Format"; + +require("./dep"); diff --git a/test/configCases/dll-plugin-format/0-create-dll/test.config.js b/test/configCases/dll-plugin-format/0-create-dll/test.config.js new file mode 100644 index 00000000000..08ea6c319c8 --- /dev/null +++ b/test/configCases/dll-plugin-format/0-create-dll/test.config.js @@ -0,0 +1 @@ +exports.noTests = true; diff --git a/test/configCases/dll-plugin-format/0-create-dll/utility.js b/test/configCases/dll-plugin-format/0-create-dll/utility.js new file mode 100644 index 00000000000..cbed57e2c2d --- /dev/null +++ b/test/configCases/dll-plugin-format/0-create-dll/utility.js @@ -0,0 +1,7 @@ +export function add(a, b) { + return a + b; +} + +export function diff(a, b) { + return a - b; +} diff --git a/test/configCases/dll-plugin-format/0-create-dll/webpack.config.js b/test/configCases/dll-plugin-format/0-create-dll/webpack.config.js new file mode 100644 index 00000000000..a9739e313e2 --- /dev/null +++ b/test/configCases/dll-plugin-format/0-create-dll/webpack.config.js @@ -0,0 +1,23 @@ +var path = require("path"); +var webpack = require("../../../../"); + +module.exports = { + entry: ["."], + resolve: { + extensions: [".js"] + }, + output: { + filename: "dll.js", + chunkFilename: "[id].dll.js", + libraryTarget: "commonjs2" + }, + plugins: [ + new webpack.DllPlugin({ + path: path.resolve( + __dirname, + "../../../js/config/dll-plugin-format/manifest0.json" + ), + format: true + }) + ] +};