Skip to content

Commit

Permalink
read your browser targets from config/targets.js automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
mansona committed Dec 5, 2024
1 parent 57e628d commit 508ef8e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
32 changes: 31 additions & 1 deletion packages/vite/src/classic-ember-support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
},
];
}
20 changes: 19 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 508ef8e

Please sign in to comment.