-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
copy assets to correct folder
- Loading branch information
Showing
8 changed files
with
69 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { ResolverLoader } from '@embroider/core'; | ||
import type { Plugin } from 'vite'; | ||
import * as process from 'process'; | ||
import { dirname, join } from 'path'; | ||
import { copyFileSync, mkdirpSync } from 'fs-extra'; | ||
import glob from 'fast-glob'; | ||
|
||
export function assets(): Plugin { | ||
const cwd = process.cwd(); | ||
const resolverLoader = new ResolverLoader(cwd); | ||
const engines = resolverLoader.resolver.options.engines; | ||
return { | ||
name: 'assets', | ||
enforce: 'pre', | ||
outputOptions(options) { | ||
options.dir = join(process.cwd(), 'dist'); | ||
}, | ||
async writeBundle(options) { | ||
const pubDir = join(process.cwd(), 'public'); | ||
const publicAppFiles = glob.sync('**/*', { | ||
cwd: pubDir, | ||
}); | ||
for (const publicAppFile of publicAppFiles) { | ||
mkdirpSync(dirname(join(options.dir!, publicAppFile))); | ||
copyFileSync(join(pubDir, publicAppFile), join(options.dir!, publicAppFile)); | ||
} | ||
for (const engine of engines) { | ||
engine.activeAddons.forEach(addon => { | ||
const pkg = resolverLoader.resolver.packageCache.ownerOfFile(addon.root); | ||
if (!pkg || !pkg.isV2Addon()) return; | ||
const assets = pkg.meta['public-assets'] || {}; | ||
Object.entries(assets).forEach(([path, dest]) => { | ||
mkdirpSync(dirname(join(options.dir!, dest))); | ||
copyFileSync(join(pkg.root, path), join(options.dir!, dest)); | ||
}); | ||
}); | ||
} | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters