- For merging json file there are lot of packages like "merge-jsons-webpack-plugin" but they restrict the file extension to json.
- But, datatables languages files have .lang extension(symbolic links might be considered but it might be cumbersome or useless effort)
- So, i decided to write it straight forward and come up with this code.
- I take advantage of CopyWebpackPlugin and did not write an extra webpack plugin.
Last active
May 30, 2018 13:03
-
-
Save expressiveco/56cb9d0531821d237d78b99efa40a1cb to your computer and use it in GitHub Desktop.
Merging json files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Extra translations for Turkish i.e. select. | |
*/ | |
{ | |
"select": { | |
"rows": { | |
"_": "%d kayıt seçildi", | |
"0": "", | |
"1": "1 kayıt seçildi" | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const webpackLib = require("./webpack.lib.js"); | |
plugins: [ | |
new CopyWebpackPlugin([ | |
{ | |
from: 'node_modules/datatables.net-plugins/i18n/Turkish.lang', | |
transform: (content, path) => { | |
// Load extra language translations. | |
const myDataTablesTurkishLang = webpackLib.readJSON("./Scripts/Turkish-Extra.lang"); | |
var dataTablesTurkishLang = webpackLib.parseJSON(content.toString('utf8')); | |
var mergedObj = Object.assign(dataTablesTurkishLang, myDataTablesTurkishLang); | |
return JSON.stringify(mergedObj, null, 2); | |
}, | |
to: 'DataTables-Lang/Turkish.json', | |
}]), | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const stripJSONComments = require("strip-json-comments"); | |
const fs = require("fs"); | |
exports.readJSON = (jsonFile) => { | |
var data = fs.readFileSync(jsonFile, 'utf8').replace(/^\uFEFF/, ''); | |
return JSON.parse(stripJSONComments(data)); | |
} | |
exports.parseJSON = (jsonString) => { | |
return JSON.parse(stripJSONComments(jsonString.replace(/^\uFEFF/, ''))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment