Skip to content

Commit 9c6f9b7

Browse files
authored
Merge pull request #1522 from escral/master
2 parents 60bda7a + 13d4379 commit 9c6f9b7

3 files changed

Lines changed: 25 additions & 9 deletions

File tree

‎src/commands/build.js‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -298,14 +298,19 @@ export default async (config = {}) => {
298298

299299
/**
300300
* Copy static files
301-
*
302-
* TODO: support an array of objects with source and destination,
303-
* i.e. static: [{ source: 'src/assets', destination: 'assets' }, ...]
304301
*/
305-
const staticSourcePaths = getRootDirectories([...new Set(get(config, 'build.static.source', []))])
302+
let staticFiles = get(config, 'build.static', [])
303+
304+
if (!Array.isArray(staticFiles)) {
305+
staticFiles = [staticFiles]
306+
}
306307

307-
for await (const rootDir of staticSourcePaths) {
308-
await cp(rootDir, path.join(buildOutputPath, get(config, 'build.static.destination')), { recursive: true })
308+
for (const definition of staticFiles) {
309+
const staticSourcePaths = getRootDirectories([...new Set(definition.source)])
310+
311+
for await (const rootDir of staticSourcePaths) {
312+
await cp(rootDir, path.join(buildOutputPath, definition.destination), { recursive: true })
313+
}
309314
}
310315

311316
const allOutputFiles = await fg.glob(path.join(buildOutputPath, '**/*'))

‎src/server/index.js‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,14 @@ export default async (config = {}) => {
252252
}
253253
})
254254

255+
let staticFiles = get(config, 'build.static', [])
256+
257+
if (!Array.isArray(staticFiles)) {
258+
staticFiles = [staticFiles]
259+
}
260+
261+
const staticFilesSourcePaths = staticFiles.flatMap((definition) => definition.source)
262+
255263
/**
256264
* Global watcher
257265
*
@@ -263,7 +271,7 @@ export default async (config = {}) => {
263271
'maizzle.config*.{js,cjs,ts}',
264272
'tailwind*.config.{js,ts}',
265273
'**/*.css',
266-
...get(config, 'build.static.source', []),
274+
...staticFilesSourcePaths,
267275
...get(config, 'server.watch', []),
268276
])
269277

@@ -365,7 +373,7 @@ export default async (config = {}) => {
365373
const srcFoldersList = await fg.glob(
366374
[
367375
'**/*/',
368-
...get(config, 'build.static.source', [])
376+
...staticFilesSourcePaths,
369377
], {
370378
onlyFiles: false,
371379
ignore: [

‎types/build.d.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@ export default interface BuildConfig {
9999
* @default undefined
100100
*/
101101
destination?: string;
102-
};
102+
} | Array<{
103+
source?: string[];
104+
destination?: string;
105+
}>
103106

104107
/**
105108
* Type of spinner to show in the console.

0 commit comments

Comments
 (0)