mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-08 13:52:36 +02:00
fix(core): allow empty static directories (#7285)
* fix(core): allow empty static directories * improve comment * add empty directory
This commit is contained in:
parent
594d8f357c
commit
e1b7171bb1
2 changed files with 28 additions and 6 deletions
|
@ -124,7 +124,11 @@ async function buildLocale({
|
||||||
outDir,
|
outDir,
|
||||||
generatedFilesDir,
|
generatedFilesDir,
|
||||||
plugins,
|
plugins,
|
||||||
siteConfig: {baseUrl, onBrokenLinks, staticDirectories},
|
siteConfig: {
|
||||||
|
baseUrl,
|
||||||
|
onBrokenLinks,
|
||||||
|
staticDirectories: staticDirectoriesOption,
|
||||||
|
},
|
||||||
routes,
|
routes,
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
|
@ -162,15 +166,30 @@ async function buildLocale({
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (staticDirectories.length > 0) {
|
// The staticDirectories option can contain empty directories, or non-existent
|
||||||
await Promise.all(staticDirectories.map((dir) => fs.ensureDir(dir)));
|
// directories (e.g. user deleted `static`). Instead of issuing an error, we
|
||||||
|
// just silently filter them out, because user could have never configured it
|
||||||
|
// in the first place (the default option should always "work").
|
||||||
|
const staticDirectories = (
|
||||||
|
await Promise.all(
|
||||||
|
staticDirectoriesOption.map(async (dir) => {
|
||||||
|
const staticDir = path.resolve(siteDir, dir);
|
||||||
|
if (
|
||||||
|
(await fs.pathExists(staticDir)) &&
|
||||||
|
(await fs.readdir(staticDir)).length > 0
|
||||||
|
) {
|
||||||
|
return staticDir;
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
).filter(Boolean);
|
||||||
|
|
||||||
|
if (staticDirectories.length > 0) {
|
||||||
serverConfig = merge(serverConfig, {
|
serverConfig = merge(serverConfig, {
|
||||||
plugins: [
|
plugins: [
|
||||||
new CopyWebpackPlugin({
|
new CopyWebpackPlugin({
|
||||||
patterns: staticDirectories
|
patterns: staticDirectories.map((dir) => ({from: dir, to: outDir})),
|
||||||
.map((dir) => path.resolve(siteDir, dir))
|
|
||||||
.map((dir) => ({from: dir, to: outDir})),
|
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
|
@ -120,6 +120,9 @@ const config = {
|
||||||
staticDirectories: [
|
staticDirectories: [
|
||||||
'static',
|
'static',
|
||||||
path.join(__dirname, '_dogfooding/_asset-tests'),
|
path.join(__dirname, '_dogfooding/_asset-tests'),
|
||||||
|
// Adding a non-existent static directory. If user deleted `static` without
|
||||||
|
// specifying `staticDirectories: []`, build should still work
|
||||||
|
path.join(__dirname, '_dogfooding/non-existent'),
|
||||||
],
|
],
|
||||||
themes: ['live-codeblock', ...dogfoodingThemeInstances],
|
themes: ['live-codeblock', ...dogfoodingThemeInstances],
|
||||||
plugins: [
|
plugins: [
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue