Skip to content

Commit

Permalink
Tell the optimizer to use esntext, and tell the test's vite config to…
Browse files Browse the repository at this point in the history
… use a newer browser target that supports top-level await
  • Loading branch information
NullVoxPopuli committed Nov 15, 2024
1 parent 20e4f8b commit f3e095c
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/vite/src/optimize-deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export function optimizeDeps(): OptimizeDeps {
exclude: ['@embroider/macros'],
extensions: ['.hbs', '.gjs', '.gts'],
esbuildOptions: {
// When optimizing deps for development,
// always allow the latest featuers
// (such as top level await)
target: 'esnext',
plugins: [esBuildResolver()],
},
};
Expand Down
74 changes: 74 additions & 0 deletions tests/scenarios/v2-addon-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,80 @@ appScenarios
`,
},
},
// Default + different build.target
'vite.config.mjs': `
import { defineConfig } from "vite";
import {
resolver,
hbs,
scripts,
templateTag,
optimizeDeps,
compatPrebuild,
assets,
contentFor,
} from "@embroider/vite";
import { resolve } from "path";
import { babel } from "@rollup/plugin-babel";
export default defineConfig(({ mode }) => {
return {
cacheDir: resolve("node_modules", ".vite"),
resolve: {
extensions: [
".mjs",
".gjs",
".js",
".mts",
".gts",
".ts",
".hbs",
".hbs.js",
".json",
],
},
plugins: [
hbs(),
templateTag(),
scripts(),
resolver(),
compatPrebuild(),
assets(),
contentFor(),
babel({
babelHelpers: "runtime",
// this needs .hbs because our hbs() plugin above converts them to
// javascript but the javascript still also needs babel, but we don't want
// to rename them because vite isn't great about knowing how to hot-reload
// them if we resolve them to made-up names.
extensions: [".gjs", ".js", ".hbs", ".ts", ".gts"],
}),
],
optimizeDeps: optimizeDeps(),
server: {
port: 4200,
},
build: {
outDir: "dist",
target: ['chrome130'],
rollupOptions: {
input: {
main: "index.html",
...(shouldBuildTests(mode)
? { tests: "tests/index.html" }
: undefined),
},
},
},
};
});
function shouldBuildTests(mode) {
return mode !== "production" || process.env.FORCE_BUILD_TESTS;
}
`,
});
})
.forEachScenario(scenario => {
Expand Down

0 comments on commit f3e095c

Please sign in to comment.