Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding format option for Dll Plugin to get a formatted manifest json. #7992 #8139

Merged
merged 4 commits into from Nov 5, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
4 changes: 4 additions & 0 deletions lib/DllPlugin.js
Expand Up @@ -20,6 +20,10 @@ class DllPlugin {
constructor(options) {
validateOptions(schema, options, "Dll Plugin");
this.options = options;

if (!options.format) {
NaviMarella marked this conversation as resolved.
Show resolved Hide resolved
this.options.format = false;
}
}

apply(compiler) {
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
})
]
};