From 471f4a94afa5d0ce701accd87942c72cbb9ca478 Mon Sep 17 00:00:00 2001 From: patrickpircher Date: Thu, 21 Dec 2023 13:12:10 +0100 Subject: [PATCH] fix vite build --- packages/vite/package.json | 3 ++- packages/vite/src/assets.ts | 12 ++++++++++++ packages/vite/src/hbs.ts | 8 +++++++- packages/vite/src/template-tag.ts | 8 +++++++- pnpm-lock.yaml | 11 +++++++---- tests/vite-app/package.json | 3 ++- 6 files changed, 37 insertions(+), 8 deletions(-) diff --git a/packages/vite/package.json b/packages/vite/package.json index 96d4cb8c72..32a041a15b 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -20,7 +20,8 @@ "fs-extra": "^10.0.0", "jsdom": "^16.6.0", "source-map-url": "^0.4.1", - "terser": "^5.7.0" + "terser": "^5.7.0", + "fast-glob": "^3.3.2" }, "devDependencies": { "@embroider/core": "workspace:^", diff --git a/packages/vite/src/assets.ts b/packages/vite/src/assets.ts index 107be3feb0..d19c64b8bc 100644 --- a/packages/vite/src/assets.ts +++ b/packages/vite/src/assets.ts @@ -3,6 +3,7 @@ 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'; @@ -13,7 +14,18 @@ export function assets(): Plugin { 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); diff --git a/packages/vite/src/hbs.ts b/packages/vite/src/hbs.ts index 3032bc713d..d15222f4d0 100644 --- a/packages/vite/src/hbs.ts +++ b/packages/vite/src/hbs.ts @@ -7,6 +7,7 @@ import { hbsToJS } from '@embroider/core'; import assertNever from 'assert-never'; import { parse as pathParse } from 'path'; import makeDebug from 'debug'; +import {RollupModuleRequest} from "./request"; const debug = makeDebug('embroider:hbs-plugin'); @@ -14,7 +15,12 @@ export function hbs(): Plugin { return { name: 'rollup-hbs-plugin', enforce: 'pre', - async resolveId(source: string, importer: string | undefined) { + async resolveId(source: string, importer: string | undefined, options) { + let request = RollupModuleRequest.from(source, importer, options.custom); + if (!request) { + // fallthrough to other rollup plugins + return null; + } let resolution = await this.resolve(source, importer, { skipSelf: true, }); diff --git a/packages/vite/src/template-tag.ts b/packages/vite/src/template-tag.ts index 17ce5d1297..4e6d999b87 100644 --- a/packages/vite/src/template-tag.ts +++ b/packages/vite/src/template-tag.ts @@ -1,6 +1,7 @@ import { createFilter } from '@rollup/pluginutils'; import type { Plugin } from 'vite'; import { Preprocessor } from 'content-tag'; +import {RollupModuleRequest} from "./request"; const gjsFilter = createFilter('**/*.gjs?(\\?)*'); @@ -15,7 +16,12 @@ export function templateTag(): Plugin { name: 'embroider-template-tag', enforce: 'pre', - async resolveId(id: string, importer: string | undefined) { + async resolveId(id: string, importer: string | undefined, options) { + let request = RollupModuleRequest.from(id, importer, options.custom); + if (!request) { + // fallthrough to other rollup plugins + return null; + } let resolution = await this.resolve(id, importer, { skipSelf: true, }); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 30ef90d0fc..9c1262328e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -929,6 +929,9 @@ importers: esbuild: specifier: ^0.17.19 version: 0.17.19 + fast-glob: + specifier: ^3.3.2 + version: 3.3.2 fs-extra: specifier: ^10.0.0 version: 10.1.0 @@ -3492,7 +3495,7 @@ packages: ember-inflector: ^4.0.2 dependencies: '@ember-data/private-build-infra': 5.3.0 - '@ember-data/store': 5.3.0(@babel/core@7.23.5)(@ember-data/tracking@5.3.0)(@ember/string@3.1.1)(@glimmer/tracking@1.1.2)(ember-source@5.1.2) + '@ember-data/store': 5.3.0(@babel/core@7.23.5)(@ember-data/tracking@5.3.0)(@ember/string@3.1.1)(ember-source@3.28.12) '@ember/string': 3.1.1 '@embroider/macros': 1.13.3(@glint/template@1.2.1) ember-cli-babel: 8.2.0(@babel/core@7.23.5) @@ -3561,7 +3564,7 @@ packages: dependencies: '@babel/core': 7.23.5(supports-color@8.1.1) '@ember-data/private-build-infra': 5.3.0 - '@ember-data/store': 5.3.0(@babel/core@7.23.5)(@ember-data/tracking@5.3.0)(@ember/string@3.1.1)(@glimmer/tracking@1.1.2)(ember-source@5.1.2) + '@ember-data/store': 5.3.0(@babel/core@7.23.5)(@ember-data/tracking@5.3.0)(@ember/string@3.1.1)(ember-source@3.28.12) '@ember/edition-utils': 1.2.0 '@ember/string': 3.1.1 '@embroider/macros': 1.13.3(@glint/template@1.2.1) @@ -3600,7 +3603,7 @@ packages: '@ember-data/store': 5.3.0 dependencies: '@ember-data/private-build-infra': 5.3.0 - '@ember-data/store': 5.3.0(@babel/core@7.23.5)(@ember-data/tracking@5.3.0)(@ember/string@3.1.1)(@glimmer/tracking@1.1.2)(ember-source@5.1.2) + '@ember-data/store': 5.3.0(@babel/core@7.23.5)(@ember-data/tracking@5.3.0)(@ember/string@3.1.1)(ember-source@3.28.12) '@ember/edition-utils': 1.2.0 '@embroider/macros': 1.13.3(@glint/template@1.2.1) ember-cli-babel: 8.2.0(@babel/core@7.23.5) @@ -3640,7 +3643,7 @@ packages: '@ember-data/graph': 5.3.0(@babel/core@7.23.5)(@ember-data/store@5.3.0) '@ember-data/private-build-infra': 5.3.0 '@ember-data/request-utils': 5.3.0(@babel/core@7.23.5) - '@ember-data/store': 5.3.0(@babel/core@7.23.5)(@ember-data/tracking@5.3.0)(@ember/string@3.1.1)(@glimmer/tracking@1.1.2)(ember-source@5.1.2) + '@ember-data/store': 5.3.0(@babel/core@7.23.5)(@ember-data/tracking@5.3.0)(@ember/string@3.1.1)(ember-source@3.28.12) '@ember/edition-utils': 1.2.0 '@embroider/macros': 1.13.3(@glint/template@1.2.1) ember-cli-babel: 8.2.0(@babel/core@7.23.5) diff --git a/tests/vite-app/package.json b/tests/vite-app/package.json index 5276f6f189..94968a02bd 100644 --- a/tests/vite-app/package.json +++ b/tests/vite-app/package.json @@ -11,7 +11,8 @@ "test": "tests" }, "scripts": { - "build": "ember build --environment=production", + "ember:build": "ember build", + "build": "vite build", "lint": "concurrently \"npm:lint:*(!fix)\" --names \"lint:\"", "lint:css": "stylelint \"**/*.css\"", "lint:css:fix": "concurrently \"npm:lint:css -- --fix\"",