Skip to content

Commit

Permalink
fix: fail to copy static image due to image compression on build
Browse files Browse the repository at this point in the history
  • Loading branch information
endiliey committed Aug 4, 2018
1 parent ef80581 commit 19153fe
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/server/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,9 @@ async function execute() {
!commander.skipImageCompression
) {
const parts = normalizedFile.split(`${sep}static${sep}`);
const targetDirectory = join(
buildDir,
parts[1].substring(0, parts[1].lastIndexOf(sep))
);
mkdirp.sync(path.dirname(targetDirectory));
const targetFile = join(buildDir, parts[1]);
const targetDirectory = path.dirname(targetFile);
mkdirp.sync(targetDirectory);
imagemin([normalizedFile], targetDirectory, {
use: [
imageminOptipng(),
Expand All @@ -261,6 +259,10 @@ async function execute() {
}),
imageminGifsicle(),
],
}).catch(error => {
// if image compression fail, just copy it as it is
console.error(error);
fs.copySync(normalizedFile, targetFile);
});
} else if (!fs.lstatSync(normalizedFile).isDirectory()) {
const parts = normalizedFile.split(`${sep}static${sep}`);
Expand Down

0 comments on commit 19153fe

Please sign in to comment.