Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #8139 from NaviMarella/FormatManifest
Adding format option for Dll Plugin to get a formatted manifest json. #7992
  • Loading branch information
sokra committed Nov 5, 2018
2 parents 4b72635 + 0140426 commit 1ea411b
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 1 deletion.
4 changes: 4 additions & 0 deletions declarations/plugins/DllPlugin.d.ts
Expand Up @@ -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')
*/
Expand Down
6 changes: 5 additions & 1 deletion lib/LibManifestPlugin.js
Expand Up @@ -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(
Expand Down
4 changes: 4 additions & 0 deletions schemas/plugins/DllPlugin.json
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions test/configCases/dll-plugin-format/0-create-dll/dep.js
@@ -0,0 +1 @@
module.exports = "foo";
4 changes: 4 additions & 0 deletions test/configCases/dll-plugin-format/0-create-dll/index.js
@@ -0,0 +1,4 @@
export { add } from "./utility";
export default "Format";

require("./dep");
@@ -0,0 +1 @@
exports.noTests = true;
7 changes: 7 additions & 0 deletions 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;
}
23 changes: 23 additions & 0 deletions 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
})
]
};

0 comments on commit 1ea411b

Please sign in to comment.