fix: copy static image as it is if image compression fail (#887)

* fix: fail to copy static image due to image compression on build

* add changelog
This commit is contained in:
Endilie Yacop Sucipto 2018-08-04 22:40:36 +08:00 committed by GitHub
parent ef80581e8e
commit 5fae14a2bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 5 deletions

View file

@ -34,6 +34,7 @@ Thank you to the following contributors who helped with this release:
- Docusaurus own search will now search the docs in the correct language & version [\#859](https://github.com/facebook/Docusaurus/pull/859)
- Fix phrase emphasis not italicized [\#850](https://github.com/facebook/Docusaurus/pull/850)
- Blogpost summary for blog feed is now properly truncated [\#880](https://github.com/facebook/Docusaurus/pull/880)
- Fix failure to copy static image if image compression fail [\#887](https://github.com/facebook/Docusaurus/pull/887)
**Chore and Maintenance**
- Remove unused files [\#881](https://github.com/facebook/Docusaurus/pull/881)

View file

@ -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(),
@ -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}`);