diff --git a/packages/compat/src/compat-app-builder.ts b/packages/compat/src/compat-app-builder.ts index 0ae235df2..7972d8c20 100644 --- a/packages/compat/src/compat-app-builder.ts +++ b/packages/compat/src/compat-app-builder.ts @@ -117,8 +117,10 @@ export class CompatAppBuilder { } } - for (let asset of this.emberEntrypoints(treePaths.htmlTree)) { - assets.push(asset); + if (treePaths.htmlTree) { + for (let asset of this.emberEntrypoints(treePaths.htmlTree)) { + assets.push(asset); + } } return assets; diff --git a/packages/vite/src/assets.ts b/packages/vite/src/assets.ts index f902e114d..92833474c 100644 --- a/packages/vite/src/assets.ts +++ b/packages/vite/src/assets.ts @@ -305,6 +305,16 @@ export function assets(options?: { entryDirectories?: string[] }): Plugin { } return readFileSync(rewrittenApp + id.replace(root + '/assets/', '/assets/').split('?')[0]).toString(); } - } + }, + async writeBundle(options) { + const { compatAppBuilder } = getCompatAppBuilder({ + rewrittenPackageCache: resolverLoader.resolver.packageCache, + root: options.dir || join(cwd, 'dist') + }); + const assets = compatAppBuilder['gatherAssets']({ + publicTree: 'public', + } as any) + await compatAppBuilder['updateAssets'](assets, [], {}); + }, } } diff --git a/packages/vite/src/build.ts b/packages/vite/src/build.ts index 7a852cb41..e1a3453ee 100644 --- a/packages/vite/src/build.ts +++ b/packages/vite/src/build.ts @@ -1,9 +1,7 @@ -import { join, dirname } from 'path'; +import { join } from 'path'; import { createHash } from 'crypto'; import { fork } from 'child_process'; -import { ResolverLoader } from '@embroider/core'; -import { existsSync, readdirSync, readFileSync, writeFileSync, copyFileSync } from 'fs'; -import { mkdirpSync } from 'fs-extra'; +import { existsSync, readdirSync, readFileSync, writeFileSync } from 'fs'; import { Plugin } from 'vite'; const cwd = process.cwd(); @@ -60,8 +58,6 @@ export async function buildIfFileChanged(path: string | null | undefined): Promi } export function build(): Plugin { - let resolverLoader = new ResolverLoader(process.cwd()); - const engine = resolverLoader.resolver.options.engines[0]; return { name: 'embroider-builder', enforce: 'pre', @@ -79,18 +75,6 @@ export function build(): Plugin { } }); }, - writeBundle(options) { - engine.activeAddons.forEach(addon => { - const pkg = resolverLoader.resolver.packageCache.ownerOfFile(addon.root); - if (!pkg) return; - if (!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)); - }); - }); - }, async buildStart() { if (!existsSync(embroiderDir)) { await emberBuild(); diff --git a/tests/vite-app/vite.config.mts b/tests/vite-app/vite.config.mts index 9fcd8906a..ec381abb5 100644 --- a/tests/vite-app/vite.config.mts +++ b/tests/vite-app/vite.config.mts @@ -42,7 +42,7 @@ export default defineConfig({ build: { rollupOptions: { input: { - main: resolve(root, "index.html"), + main: resolve('.', "index.html"), tests: resolve(".", "tests/index.html"), }, },