From 71f92303838fc0edee4a9dc11098fb38c521e533 Mon Sep 17 00:00:00 2001 From: Naveen Marella Date: Wed, 3 Oct 2018 09:48:29 -0600 Subject: [PATCH 1/4] Adding format option for Dll Plugin to get a formatted manifest json. --- declarations/plugins/DllPlugin.d.ts | 4 ++++ lib/DllPlugin.js | 4 ++++ lib/LibManifestPlugin.js | 6 +++++- schemas/plugins/DllPlugin.json | 4 ++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/declarations/plugins/DllPlugin.d.ts b/declarations/plugins/DllPlugin.d.ts index f7264c2dab3..6f1eadf9410 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/DllPlugin.js b/lib/DllPlugin.js index 884c21c5821..ee0f8a82999 100644 --- a/lib/DllPlugin.js +++ b/lib/DllPlugin.js @@ -20,6 +20,10 @@ class DllPlugin { constructor(options) { validateOptions(schema, options, "Dll Plugin"); this.options = options; + + if (!options.format) { + this.options.format = false; + } } apply(compiler) { 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", From 18ef6785617a7fb665d5d40d55393e5f84564b73 Mon Sep 17 00:00:00 2001 From: Naveen Marella Date: Wed, 3 Oct 2018 10:12:05 -0600 Subject: [PATCH 2/4] Fixed liniting issue in DllPlugin ts file. --- declarations/plugins/DllPlugin.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/declarations/plugins/DllPlugin.d.ts b/declarations/plugins/DllPlugin.d.ts index 6f1eadf9410..addbce540f1 100644 --- a/declarations/plugins/DllPlugin.d.ts +++ b/declarations/plugins/DllPlugin.d.ts @@ -14,7 +14,7 @@ export interface DllPluginOptions { */ entryOnly?: boolean; /** - * If true, manifest json file(output) will be formatted + * If true, manifest json file (output) will be formatted */ format?: boolean; /** From 78e64b6cc5ad4c4490040ad92018480e5d80777a Mon Sep 17 00:00:00 2001 From: Naveen Marella Date: Wed, 3 Oct 2018 13:16:07 -0600 Subject: [PATCH 3/4] Added unit test to generate formatted manifest json --- .../dll-plugin-format/0-create-dll/dep.js | 1 + .../dll-plugin-format/0-create-dll/index.js | 4 ++++ .../0-create-dll/test.config.js | 1 + .../dll-plugin-format/0-create-dll/utility.js | 7 ++++++ .../0-create-dll/webpack.config.js | 23 +++++++++++++++++++ 5 files changed, 36 insertions(+) create mode 100644 test/configCases/dll-plugin-format/0-create-dll/dep.js create mode 100644 test/configCases/dll-plugin-format/0-create-dll/index.js create mode 100644 test/configCases/dll-plugin-format/0-create-dll/test.config.js create mode 100644 test/configCases/dll-plugin-format/0-create-dll/utility.js create mode 100644 test/configCases/dll-plugin-format/0-create-dll/webpack.config.js 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 + }) + ] +}; From 014042605f3b3b9cf566524406e8353fd50078ad Mon Sep 17 00:00:00 2001 From: Naveen Marella Date: Thu, 4 Oct 2018 09:49:43 -0600 Subject: [PATCH 4/4] Removed unnecessary change on passed object. --- lib/DllPlugin.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/DllPlugin.js b/lib/DllPlugin.js index ee0f8a82999..884c21c5821 100644 --- a/lib/DllPlugin.js +++ b/lib/DllPlugin.js @@ -20,10 +20,6 @@ class DllPlugin { constructor(options) { validateOptions(schema, options, "Dll Plugin"); this.options = options; - - if (!options.format) { - this.options.format = false; - } } apply(compiler) {