Skip to content

Commit

Permalink
perf: uglify json files (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
orzyyyy authored Sep 29, 2019
1 parent ebf4855 commit 43e464e
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions nino.koei.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,39 @@ const fs = require('fs-extra');

const initMappingFiles = () => {
const assetsFiles = fs.readdirSync(path.join(__dirname, 'src/assets'));
const mappingFile = path.join(__dirname, 'src/assets/mapping.json');
const targetFiles = fs
.readJsonSync(mappingFile)
.filter(item => item.visible !== false && !assetsFiles.includes(item.id));
const mappingFilePath = path.join(__dirname, 'src/assets/mapping.json');
const mappingFile = fs
.readJsonSync(mappingFilePath)
.filter(item => item.visible !== false);

const targetFiles = mappingFile.filter(
item => !assetsFiles.includes(item.id),
);

if (process.env.BUILD_ENV === 'prod') {
fs.outputJsonSync(mappingFilePath, mappingFile, {
spaces: 0,
});

const siderFilePath = path.join(__dirname, 'src/assets/sider.json');
const siderFile = fs.readJsonSync(siderFilePath);
fs.outputJsonSync(siderFilePath, siderFile, {
spaces: 0,
});

fs.readdirSync(path.join(__dirname, 'src/assets/mapping')).map(item => {
for (const mapping of mappingFile) {
if (item.includes(mapping.id)) {
const mapPath = path.join(__dirname, 'src/assets/mapping', item);
const mapFile = fs.readJsonSync(mapPath);
fs.outputJsonSync(mapPath, mapFile, {
spaces: 0,
});
}
}
});
}

return targetFiles;
};

Expand Down

0 comments on commit 43e464e

Please sign in to comment.