Skip to content
This repository was archived by the owner on Aug 4, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ export default {

// specify indentation for the generated default export —
// defaults to '\t'
indent: ' '
indent: ' ',

// ignores indent and generates the smallest code
compact: true, // Default: false

// generate a named export for every property of the JSON object
namedExports: true // Default: true
})
]
};
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@
"license": "MIT",
"repository": "rollup/rollup-plugin-json",
"dependencies": {
"rollup-pluginutils": "^2.2.0"
"rollup-pluginutils": "^2.3.0"
}
}
7 changes: 6 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ export default function json (options = {}) {
}

return {
code: dataToEsm(data, {preferConst: options.preferConst, indent}),
code: dataToEsm(data, {
preferConst: options.preferConst,
compact: options.compact,
namedExports: options.namedExports,
indent
}),
map: {mappings: ''}
};
}
Expand Down
1 change: 1 addition & 0 deletions test/samples/form/compact.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export var validKey=true;export var nested={subKey:"ok"};export var array=[1,"2"];export default{validKey:validKey,"invalid-key": 1,nested:nested,array:array,"function": "not used","null": null};
3 changes: 2 additions & 1 deletion test/samples/form/customIndent.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ export default {
"invalid-key": 1,
nested: nested,
array: array,
"function": "not used"
"function": "not used",
"null": null
};
3 changes: 2 additions & 1 deletion test/samples/form/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ export default {
"invalid-key": 1,
nested: nested,
array: array,
"function": "not used"
"function": "not used",
"null": null
};
3 changes: 2 additions & 1 deletion test/samples/form/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"subKey": "ok"
},
"array": [1, "2"],
"function": "not used"
"function": "not used",
"null": null
}
13 changes: 13 additions & 0 deletions test/samples/form/namedExports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export default {
validKey: true,
"invalid-key": 1,
nested: {
subKey: "ok"
},
array: [
1,
"2"
],
"function": "not used",
"null": null
};
3 changes: 2 additions & 1 deletion test/samples/form/preferConst.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ export default {
"invalid-key": 1,
nested: nested,
array: array,
"function": "not used"
"function": "not used",
"null": null
};
14 changes: 14 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,20 @@ describe('rollup-plugin-json', () => {
read('samples/form/customIndent.js')
);
});

it('generates correct code with compact=true', () => {
assert.deepEqual(
json({ compact: true }).transform(read('samples/form/input.json'), 'input.json').code + '\n',
read('samples/form/compact.js')
);
});

it('generates correct code with namedExports=false', () => {
assert.deepEqual(
json({ namedExports: false }).transform(read('samples/form/input.json'), 'input.json').code + '\n',
read('samples/form/namedExports.js')
);
});
});

function read (file) {
Expand Down