From 508ef8e11ea68960bb2828c63e6f1c0a9a3dd0c3 Mon Sep 17 00:00:00 2001 From: Chris Manson Date: Thu, 5 Dec 2024 15:44:04 +0000 Subject: [PATCH 1/3] read your browser targets from config/targets.js automatically --- packages/vite/package.json | 1 + packages/vite/src/classic-ember-support.ts | 32 +++++++++++++++++++++- pnpm-lock.yaml | 20 +++++++++++++- 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/packages/vite/package.json b/packages/vite/package.json index 1a4204309..3b8e75c01 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -21,6 +21,7 @@ "@embroider/reverse-exports": "workspace:*", "@rollup/pluginutils": "^5.1.0", "assert-never": "^1.2.1", + "browserslist-to-esbuild": "^2.1.1", "content-tag": "^2.0.2", "debug": "^4.3.2", "esbuild": "^0.17.19", diff --git a/packages/vite/src/classic-ember-support.ts b/packages/vite/src/classic-ember-support.ts index 93c1e4539..fa1168c3b 100644 --- a/packages/vite/src/classic-ember-support.ts +++ b/packages/vite/src/classic-ember-support.ts @@ -3,7 +3,37 @@ import { scripts } from './scripts.js'; import { compatPrebuild } from './build.js'; import { assets } from './assets.js'; import { contentFor } from './content-for.js'; +import browserslistToEsbuild from 'browserslist-to-esbuild'; +import { existsSync } from 'fs'; +import { join } from 'path'; +import { mergeConfig, type UserConfig } from 'vite'; export function classicEmberSupport() { - return [hbs(), scripts(), compatPrebuild(), assets(), contentFor()]; + return [ + hbs(), + scripts(), + compatPrebuild(), + assets(), + contentFor(), + { + name: 'vite-plugin-ember-browser-targets', + async config(userConfig: UserConfig) { + const targetsPath = join(process.cwd(), 'config/targets.js'); + if (existsSync(targetsPath)) { + const targets = await import(targetsPath); + if (targets.default.browsers) { + return mergeConfig( + { + build: { + target: browserslistToEsbuild(targets.browsers), + }, + }, + userConfig + ); + } + } + return userConfig; + }, + }, + ]; } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fb6a276a4..bb19267ea 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1002,6 +1002,9 @@ importers: assert-never: specifier: ^1.2.1 version: 1.3.0 + browserslist-to-esbuild: + specifier: ^2.1.1 + version: 2.1.1 content-tag: specifier: ^2.0.2 version: 2.0.3 @@ -3632,7 +3635,7 @@ packages: peerDependencies: '@babel/core': ^7.0.0-0 dependencies: - '@babel/core': 7.26.0(supports-color@8.1.1) + '@babel/core': 7.26.0 '@babel/helper-plugin-utils': 7.25.9 /@babel/plugin-transform-private-methods@7.25.9(@babel/core@7.26.0): @@ -11208,6 +11211,16 @@ packages: /browser-process-hrtime@1.0.0: resolution: {integrity: sha512-9o5UecI3GhkpM6DrXr69PblIuWxPKk9Y0jHBRhdocZ2y7YECBFCsHm79Pr3OyR2AvjhDkabFJaDJMYRazHgsow==} + /browserslist-to-esbuild@2.1.1: + resolution: {integrity: sha512-KN+mty6C3e9AN8Z5dI1xeN15ExcRNeISoC3g7V0Kax/MMF9MSoYA2G7lkTTcVUFntiEjkpI0HNgqJC1NjdyNUw==} + engines: {node: '>=18'} + hasBin: true + peerDependencies: + browserslist: ^4.14.0 + dependencies: + meow: 13.2.0 + dev: false + /browserslist@4.24.2: resolution: {integrity: sha512-ZIc+Q62revdMcqC6aChtW4jz3My3klmCO1fEmINZY/8J3EpBg5/A/D0AKmBveUh6pgoeycoMkVMko84tuYS+Gg==} engines: {node: ^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7} @@ -21332,6 +21345,11 @@ packages: yargs-parser: 20.2.9 dev: true + /meow@13.2.0: + resolution: {integrity: sha512-pxQJQzB6djGPXh08dacEloMFopsOqGVRKFPYvPOt9XDZ1HasbgDZA74CJGreSU4G3Ak7EFJGoiH2auq+yXISgA==} + engines: {node: '>=18'} + dev: false + /merge-descriptors@1.0.3: resolution: {integrity: sha512-gaNvAS7TZ897/rVaZ0nMtAyxNyi/pdbjbAwUpFQpN70GqnVfOiXpeUUMKRBmzXaSQ8DdTX4/0ms62r2K+hE6mQ==} From 53a6260f3fc691a2db90b59d43d861a1bafdbf42 Mon Sep 17 00:00:00 2001 From: Chris Manson Date: Thu, 5 Dec 2024 17:43:17 +0000 Subject: [PATCH 2/3] add browserslist as a dependency of @embroider/vite --- packages/vite/package.json | 1 + pnpm-lock.yaml | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/vite/package.json b/packages/vite/package.json index 3b8e75c01..cf7a0f4bd 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -21,6 +21,7 @@ "@embroider/reverse-exports": "workspace:*", "@rollup/pluginutils": "^5.1.0", "assert-never": "^1.2.1", + "browserslist": "*", "browserslist-to-esbuild": "^2.1.1", "content-tag": "^2.0.2", "debug": "^4.3.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bb19267ea..0ba37dc0e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1002,9 +1002,12 @@ importers: assert-never: specifier: ^1.2.1 version: 1.3.0 + browserslist: + specifier: ^4.14.0 + version: 4.24.2 browserslist-to-esbuild: specifier: ^2.1.1 - version: 2.1.1 + version: 2.1.1(browserslist@4.24.2) content-tag: specifier: ^2.0.2 version: 2.0.3 @@ -11211,13 +11214,14 @@ packages: /browser-process-hrtime@1.0.0: resolution: {integrity: sha512-9o5UecI3GhkpM6DrXr69PblIuWxPKk9Y0jHBRhdocZ2y7YECBFCsHm79Pr3OyR2AvjhDkabFJaDJMYRazHgsow==} - /browserslist-to-esbuild@2.1.1: + /browserslist-to-esbuild@2.1.1(browserslist@4.24.2): resolution: {integrity: sha512-KN+mty6C3e9AN8Z5dI1xeN15ExcRNeISoC3g7V0Kax/MMF9MSoYA2G7lkTTcVUFntiEjkpI0HNgqJC1NjdyNUw==} engines: {node: '>=18'} hasBin: true peerDependencies: browserslist: ^4.14.0 dependencies: + browserslist: 4.24.2 meow: 13.2.0 dev: false From 1b692d800d49d6a7841209daae9ea747db6b4ae8 Mon Sep 17 00:00:00 2001 From: Chris Manson Date: Thu, 5 Dec 2024 22:02:23 +0000 Subject: [PATCH 3/3] fix targets path on windows --- packages/vite/src/classic-ember-support.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/classic-ember-support.ts b/packages/vite/src/classic-ember-support.ts index fa1168c3b..d9e9ab792 100644 --- a/packages/vite/src/classic-ember-support.ts +++ b/packages/vite/src/classic-ember-support.ts @@ -7,6 +7,7 @@ import browserslistToEsbuild from 'browserslist-to-esbuild'; import { existsSync } from 'fs'; import { join } from 'path'; import { mergeConfig, type UserConfig } from 'vite'; +import { pathToFileURL } from 'url'; export function classicEmberSupport() { return [ @@ -20,7 +21,7 @@ export function classicEmberSupport() { async config(userConfig: UserConfig) { const targetsPath = join(process.cwd(), 'config/targets.js'); if (existsSync(targetsPath)) { - const targets = await import(targetsPath); + const targets = await import(pathToFileURL(targetsPath).toString()); if (targets.default.browsers) { return mergeConfig( {