@nullvoxpopuli/ember-vite 1.3.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +11 -0
- package/package.json +1 -1
- package/src/ember.test.ts +37 -2
- package/src/ember.ts +13 -0
package/dist/index.js
CHANGED
|
@@ -190,6 +190,7 @@ function ember(nvpConfig = {}) {
|
|
|
190
190
|
* and takes its esbuild path without it.
|
|
191
191
|
*/
|
|
192
192
|
await emberConfig.call(this, viteConfig, env);
|
|
193
|
+
applyPreviewPort(viteConfig);
|
|
193
194
|
if ("plugins" in babel) {
|
|
194
195
|
babel.plugins.length = 0;
|
|
195
196
|
for (const plugin of defaultBabelPlugins(env.mode)) babel.plugins.push(plugin);
|
|
@@ -228,6 +229,16 @@ function ember(nvpConfig = {}) {
|
|
|
228
229
|
})
|
|
229
230
|
];
|
|
230
231
|
}
|
|
232
|
+
/**
|
|
233
|
+
* `vite preview` serves the build on `$PORT`, the port that hosts and CI give,
|
|
234
|
+
* or on 4200, the port of the dev server.
|
|
235
|
+
* Vite itself reads no `$PORT`, and `@embroider/vite` only sets the dev server's port.
|
|
236
|
+
* A port in the project's own vite config wins.
|
|
237
|
+
*/
|
|
238
|
+
function applyPreviewPort(viteConfig) {
|
|
239
|
+
viteConfig.preview ||= {};
|
|
240
|
+
viteConfig.preview.port ??= Number(process.env.PORT) || 4200;
|
|
241
|
+
}
|
|
231
242
|
const MODE_DEV = "development";
|
|
232
243
|
function isDev(mode) {
|
|
233
244
|
return mode === MODE_DEV;
|
package/package.json
CHANGED
package/src/ember.test.ts
CHANGED
|
@@ -7,8 +7,7 @@ import { ember } from "./ember.ts";
|
|
|
7
7
|
|
|
8
8
|
const ROLLDOWN = { meta: { rolldownVersion: "1.0.0" } } as ConfigPluginContext;
|
|
9
9
|
|
|
10
|
-
async function configure(env: ConfigEnv) {
|
|
11
|
-
const config: any = {};
|
|
10
|
+
async function configure(env: ConfigEnv, config: any = {}) {
|
|
12
11
|
const [plugin] = ember();
|
|
13
12
|
|
|
14
13
|
// @ts-expect-error the first entry is the config plugin
|
|
@@ -30,6 +29,42 @@ describe("ember", () => {
|
|
|
30
29
|
expect(config.optimizeDeps.exclude).toContain("@embroider/macros");
|
|
31
30
|
});
|
|
32
31
|
|
|
32
|
+
describe("preview port", () => {
|
|
33
|
+
const original = process.env.PORT;
|
|
34
|
+
|
|
35
|
+
afterEach(() => {
|
|
36
|
+
if (original === undefined) delete process.env.PORT;
|
|
37
|
+
else process.env.PORT = original;
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("is 4200 without $PORT, like the dev server", async () => {
|
|
41
|
+
delete process.env.PORT;
|
|
42
|
+
|
|
43
|
+
const config = await configure({ command: "serve", mode: "production" });
|
|
44
|
+
|
|
45
|
+
expect(config.preview.port).toBe(4200);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("comes from $PORT", async () => {
|
|
49
|
+
process.env.PORT = "3123";
|
|
50
|
+
|
|
51
|
+
const config = await configure({ command: "serve", mode: "production" });
|
|
52
|
+
|
|
53
|
+
expect(config.preview.port).toBe(3123);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("keeps the port in the project's vite config", async () => {
|
|
57
|
+
process.env.PORT = "3123";
|
|
58
|
+
|
|
59
|
+
const config = await configure(
|
|
60
|
+
{ command: "serve", mode: "production" },
|
|
61
|
+
{ preview: { port: 8080 } },
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
expect(config.preview.port).toBe(8080);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
33
68
|
it("gives @embroider/vite the plugin context, so that it configures rolldown", async () => {
|
|
34
69
|
const config = await configure({ command: "build", mode: "production" });
|
|
35
70
|
|
package/src/ember.ts
CHANGED
|
@@ -225,6 +225,8 @@ export function ember(nvpConfig: Config = {}) {
|
|
|
225
225
|
*/
|
|
226
226
|
await emberConfig.call(this, viteConfig, env);
|
|
227
227
|
|
|
228
|
+
applyPreviewPort(viteConfig);
|
|
229
|
+
|
|
228
230
|
if ("plugins" in babel) {
|
|
229
231
|
babel.plugins.length = 0;
|
|
230
232
|
|
|
@@ -281,6 +283,17 @@ export function ember(nvpConfig: Config = {}) {
|
|
|
281
283
|
];
|
|
282
284
|
}
|
|
283
285
|
|
|
286
|
+
/**
|
|
287
|
+
* `vite preview` serves the build on `$PORT`, the port that hosts and CI give,
|
|
288
|
+
* or on 4200, the port of the dev server.
|
|
289
|
+
* Vite itself reads no `$PORT`, and `@embroider/vite` only sets the dev server's port.
|
|
290
|
+
* A port in the project's own vite config wins.
|
|
291
|
+
*/
|
|
292
|
+
function applyPreviewPort(viteConfig: UserConfig) {
|
|
293
|
+
viteConfig.preview ||= {};
|
|
294
|
+
viteConfig.preview.port ??= Number(process.env.PORT) || 4200;
|
|
295
|
+
}
|
|
296
|
+
|
|
284
297
|
const MODE_DEV = "development";
|
|
285
298
|
|
|
286
299
|
function isDev(mode: string) {
|