Skip to content

Commit

Permalink
require only when needed, use v8-compile-cache
Browse files Browse the repository at this point in the history
  • Loading branch information
astronomersiva committed Jan 19, 2019
1 parent 7d16b5b commit 5f29aa3
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 24 deletions.
1 change: 1 addition & 0 deletions lib/lego.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// require('time-require');
require('v8-compile-cache');

const chalk = require('chalk');

Expand Down
12 changes: 8 additions & 4 deletions lib/tasks/copyMinorStaticAssets.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ module.exports = async function(site) {
let staticFiles = cleanFileList(fs.readdirSync(STATIC));
let minorStaticFiles = staticFiles.filter((path) => !['css', 'js'].includes(path));

// Need to investigate why sync is faster than async equivalent here
let copyPromises = [];
for (const asset of minorStaticFiles) {
fs.copySync(
`${STATIC}/${asset}`,
`${BUILD}/${STATIC}/${asset}`
copyPromises.push(
fs.copy(
`${STATIC}/${asset}`,
`${BUILD}/${STATIC}/${asset}`
)
);
}

await Promise.all(copyPromises);
} catch (error) {
throw error;
}
Expand Down
9 changes: 5 additions & 4 deletions lib/utils/loadData.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
module.exports = function(logger) {
const fs = require('fs-extra');
const path = require('path');
const chalk = require('chalk');
const YAML = require('yaml').default;

const filterFileList = require('./filterFileList');
const { DATA } = require('./constants');

if (!fs.existsSync(DATA)) {
return {};
}

const path = require('path');
const chalk = require('chalk');

const YAML = require('yaml').default;

let files = fs.readdirSync(DATA);
let ymlFiles = filterFileList(files, ['yml', 'yaml']);
let data = {};
Expand Down
30 changes: 15 additions & 15 deletions lib/utils/minifyHtml.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
const findUp = require('find-up');
const { minify } = require('html-minifier');

let configFile = findUp.sync('lego.js');
let config = {
collapseWhitespace: true,
minifyJS: true,
minifyCSS: true,
removeComments: true
};

if (configFile) {
config = Object.assign(config, require(configFile).htmlMinifier);
}

module.exports = function(html, isDevelopment) {
try {
if (isDevelopment) {
return html;
}

const findUp = require('find-up');
const { minify } = require('html-minifier');

let configFile = findUp.sync('lego.js');
let config = {
collapseWhitespace: true,
minifyJS: true,
minifyCSS: true,
removeComments: true
};

if (configFile) {
config = Object.assign(config, require(configFile).htmlMinifier);
}

return minify(html, config);
} catch (error) {
throw error;
Expand Down
7 changes: 6 additions & 1 deletion package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"sharp": "^0.20.5",
"signale": "^1.2.1",
"terser": "^3.10.13",
"v8-compile-cache": "^2.0.2",
"yaml": "^1.0.0-rc.8"
}
}

0 comments on commit 5f29aa3

Please sign in to comment.