@nullvoxpopuli/ember-vite 1.1.0 → 1.2.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/README.md +10 -11
- package/dist/index.js +45 -37
- package/package.json +3 -3
- package/src/ember.ts +44 -36
- package/src/test-html.ts +13 -11
package/README.md
CHANGED
|
@@ -8,30 +8,29 @@ A speed-optimized default meta-config for ember projects.
|
|
|
8
8
|
npm add @nullvoxpopuli/ember-vite
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
Requires node 24
|
|
12
|
-
|
|
13
|
-
`esnext`).
|
|
11
|
+
Requires node 24+. These packages ship TypeScript source, so type-checking
|
|
12
|
+
needs TypeScript 6+ with `lib` covering `es2025` (for example `esnext`).
|
|
14
13
|
|
|
15
14
|
## Usage
|
|
16
15
|
|
|
17
|
-
|
|
16
|
+
In your vite config:
|
|
18
17
|
|
|
19
18
|
```js
|
|
20
19
|
import { defineConfig } from "vite";
|
|
21
20
|
import { ember } from "@nullvoxpopuli/ember-vite";
|
|
22
21
|
|
|
23
22
|
export default defineConfig({
|
|
24
|
-
plugins: [
|
|
25
|
-
|
|
26
|
-
],
|
|
27
|
-
}
|
|
23
|
+
plugins: [ember()],
|
|
24
|
+
});
|
|
28
25
|
```
|
|
29
26
|
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
Then:
|
|
28
|
+
|
|
29
|
+
1. Remove any plugins from embroider or babel.
|
|
30
|
+
2. Delete from your package.json: `@rollup/plugin-babel`, `@embroider/core`, `@embroider/vite`.
|
|
32
31
|
|
|
33
32
|
> [!NOTE]
|
|
34
|
-
>
|
|
33
|
+
> Linting still needs the babel related deps, so keep those.
|
|
35
34
|
|
|
36
35
|
## Requirements
|
|
37
36
|
|
package/dist/index.js
CHANGED
|
@@ -5,10 +5,10 @@ import { join, resolve } from "node:path";
|
|
|
5
5
|
import { maybeBabel, maybeBabel as maybeBabel$1 } from "@nullvoxpopuli/ember-build-tooling-utils";
|
|
6
6
|
//#region src/test-html.ts
|
|
7
7
|
/**
|
|
8
|
-
* Everything a QUnit + testem run needs, with no project-specific
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* co-located `*-test` modules under src
|
|
8
|
+
* Everything a QUnit + testem run needs, with no project-specific references.
|
|
9
|
+
*
|
|
10
|
+
* - root-relative specifiers keep it independent of where the project keeps its files
|
|
11
|
+
* - the globs pick up tests/** as well as co-located `*-test` modules under src/**
|
|
12
12
|
*/
|
|
13
13
|
const DEFAULT_TEST_HTML = `<!doctype html>
|
|
14
14
|
<html>
|
|
@@ -40,14 +40,16 @@ const DEFAULT_TEST_HTML = `<!doctype html>
|
|
|
40
40
|
</html>
|
|
41
41
|
`;
|
|
42
42
|
/**
|
|
43
|
-
* Lets a project run its tests without maintaining a tests/index.html
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* `
|
|
48
|
-
*
|
|
43
|
+
* Lets a project run its tests without maintaining a tests/index.html.
|
|
44
|
+
*
|
|
45
|
+
* Whenever that file is absent, this plugin answers for it:
|
|
46
|
+
* - `load` supplies the html to the build
|
|
47
|
+
* (so `tests/index.html` still lands in dist for testem)
|
|
48
|
+
* - the dev-server middleware serves it, through `transformIndexHtml`,
|
|
49
|
+
* so the html goes through the same pipeline as an on-disk file
|
|
49
50
|
*
|
|
50
|
-
* A tests/index.html on disk always wins
|
|
51
|
+
* A tests/index.html on disk always wins.
|
|
52
|
+
* Every hook here defers to it.
|
|
51
53
|
*/
|
|
52
54
|
function testHtml() {
|
|
53
55
|
const htmlPath = join(process.cwd(), "tests", "index.html");
|
|
@@ -82,14 +84,16 @@ function absolutePath(relativePath) {
|
|
|
82
84
|
* Everything a project without its own babel config needs:
|
|
83
85
|
*
|
|
84
86
|
* - TypeScript stripping
|
|
85
|
-
* - template compilation
|
|
86
|
-
* project's own ember-source,
|
|
87
|
+
* - template compilation, to the wire format
|
|
88
|
+
* (vite serves and bundles for the project's own ember-source,
|
|
89
|
+
* so the final compile happens here)
|
|
87
90
|
* - build macros, evaluated at build time
|
|
88
|
-
* - decorator-transforms, with its runtime left as a bare specifier
|
|
89
|
-
* resolves from the project
|
|
91
|
+
* - decorator-transforms, with its runtime left as a bare specifier
|
|
92
|
+
* so it resolves from the project
|
|
93
|
+
* (the project depends on `decorator-transforms`)
|
|
90
94
|
*
|
|
91
|
-
* The plugins are named, not imported
|
|
92
|
-
* project, which carries them as its own dependencies.
|
|
95
|
+
* The plugins are named, not imported.
|
|
96
|
+
* babel resolves them from the project, which carries them as its own dependencies.
|
|
93
97
|
*/
|
|
94
98
|
function defaultBabelPlugins() {
|
|
95
99
|
const macros = buildMacros();
|
|
@@ -105,12 +109,14 @@ function defaultBabelPlugins() {
|
|
|
105
109
|
];
|
|
106
110
|
}
|
|
107
111
|
/**
|
|
108
|
-
* The project's babel config wins when it exists
|
|
109
|
-
* selects which one (e.g. a test-only `config/test/babel.config.js`).
|
|
110
|
-
*
|
|
111
|
-
* templates, macros, and decorators,
|
|
112
|
-
*
|
|
113
|
-
*
|
|
112
|
+
* The project's babel config wins when it exists.
|
|
113
|
+
* `babel.configFile` selects which one (e.g. a test-only `config/test/babel.config.js`).
|
|
114
|
+
*
|
|
115
|
+
* Without one (libraries), `defaultBabelPlugins` covers TypeScript, templates, macros, and decorators,
|
|
116
|
+
* so no config file is required.
|
|
117
|
+
*
|
|
118
|
+
* Helpers are inlined in that case:
|
|
119
|
+
* projects without a babel config don't carry `@babel/runtime`.
|
|
114
120
|
*/
|
|
115
121
|
function babelOptions(nvpConfig) {
|
|
116
122
|
const configFile = resolve(join(process.cwd(), nvpConfig.babel?.configFile ?? "./babel.config.js"));
|
|
@@ -125,9 +131,12 @@ function babelOptions(nvpConfig) {
|
|
|
125
131
|
/**
|
|
126
132
|
* Additional opt-ins beyond maybeBabel's built-in list.
|
|
127
133
|
*
|
|
128
|
-
* These libraries ship code that still needs babel
|
|
129
|
-
*
|
|
130
|
-
*
|
|
134
|
+
* These libraries ship code that still needs babel:
|
|
135
|
+
* - ember-concurrency's decorators
|
|
136
|
+
* - ember-scoped-css transforms
|
|
137
|
+
* - ember-intl's formatMessage macro
|
|
138
|
+
*
|
|
139
|
+
* The `initializeRuntimeMacrosConfig` runtime call must also be compiled away.
|
|
131
140
|
*/
|
|
132
141
|
function babelFilter(nvpConfig) {
|
|
133
142
|
return { include: {
|
|
@@ -191,14 +200,12 @@ function applyConfig(viteConfig, env, nvpConfig) {
|
|
|
191
200
|
return prod(viteConfig, nvpConfig);
|
|
192
201
|
}
|
|
193
202
|
function dev(viteConfig, nvpConfig) {
|
|
194
|
-
|
|
195
|
-
*
|
|
203
|
+
/**
|
|
196
204
|
* build config for tests
|
|
197
205
|
*
|
|
198
|
-
* NOTE: we can't minify
|
|
199
|
-
*
|
|
200
|
-
|
|
201
|
-
*************************************/
|
|
206
|
+
* NOTE: we can't minify.
|
|
207
|
+
* some tests check x.constructor.name, which changes when minified
|
|
208
|
+
*/
|
|
202
209
|
Object.assign(viteConfig.build, {
|
|
203
210
|
sourcemap: true,
|
|
204
211
|
cleanCssOptions: { sourceMap: true },
|
|
@@ -262,7 +269,8 @@ function prod(viteConfig, nvpConfig) {
|
|
|
262
269
|
minify: true,
|
|
263
270
|
cleanDir: true,
|
|
264
271
|
/**
|
|
265
|
-
*
|
|
272
|
+
* Needed due to how we manage module state.
|
|
273
|
+
*
|
|
266
274
|
* This can create waterfalls when too much top-level await is used.
|
|
267
275
|
*/
|
|
268
276
|
strictExecutionOrder: true,
|
|
@@ -271,10 +279,10 @@ function prod(viteConfig, nvpConfig) {
|
|
|
271
279
|
*/
|
|
272
280
|
codeSplitting: {
|
|
273
281
|
/**
|
|
274
|
-
* Kind of a shame this isn't automatic based on dynamic import usage
|
|
275
|
-
*
|
|
276
|
-
*
|
|
277
|
-
* rather than rely on automatic optimizations based on import/module usage
|
|
282
|
+
* Kind of a shame this isn't automatic based on dynamic import usage in vite8.
|
|
283
|
+
*
|
|
284
|
+
* This forces us to know every potential problem area of the app,
|
|
285
|
+
* rather than rely on automatic optimizations based on import/module usage.
|
|
278
286
|
*/
|
|
279
287
|
groups: [...nvpConfig?.production?.codeSplittingGroups ?? []] }
|
|
280
288
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nullvoxpopuli/ember-vite",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Meta plugin for ember projects focusing on speed.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -17,11 +17,11 @@
|
|
|
17
17
|
"directory": "packages/vite"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@babel/core": "^7.28.10",
|
|
20
|
+
"@babel/core": "^7.28.10 || ^8.0.0",
|
|
21
21
|
"@embroider/core": "^4.4.2",
|
|
22
22
|
"@embroider/macros": "^1.20.3",
|
|
23
23
|
"@embroider/vite": "^1.5.0",
|
|
24
|
-
"@nullvoxpopuli/ember-build-tooling-utils": "1.
|
|
24
|
+
"@nullvoxpopuli/ember-build-tooling-utils": "1.2.0"
|
|
25
25
|
},
|
|
26
26
|
"engines": {
|
|
27
27
|
"node": ">= 24"
|
package/src/ember.ts
CHANGED
|
@@ -19,14 +19,16 @@ function absolutePath(relativePath: string) {
|
|
|
19
19
|
* Everything a project without its own babel config needs:
|
|
20
20
|
*
|
|
21
21
|
* - TypeScript stripping
|
|
22
|
-
* - template compilation
|
|
23
|
-
* project's own ember-source,
|
|
22
|
+
* - template compilation, to the wire format
|
|
23
|
+
* (vite serves and bundles for the project's own ember-source,
|
|
24
|
+
* so the final compile happens here)
|
|
24
25
|
* - build macros, evaluated at build time
|
|
25
|
-
* - decorator-transforms, with its runtime left as a bare specifier
|
|
26
|
-
* resolves from the project
|
|
26
|
+
* - decorator-transforms, with its runtime left as a bare specifier
|
|
27
|
+
* so it resolves from the project
|
|
28
|
+
* (the project depends on `decorator-transforms`)
|
|
27
29
|
*
|
|
28
|
-
* The plugins are named, not imported
|
|
29
|
-
* project, which carries them as its own dependencies.
|
|
30
|
+
* The plugins are named, not imported.
|
|
31
|
+
* babel resolves them from the project, which carries them as its own dependencies.
|
|
30
32
|
*/
|
|
31
33
|
function defaultBabelPlugins() {
|
|
32
34
|
const macros = buildMacros();
|
|
@@ -56,12 +58,14 @@ type BabelOptions =
|
|
|
56
58
|
};
|
|
57
59
|
|
|
58
60
|
/**
|
|
59
|
-
* The project's babel config wins when it exists
|
|
60
|
-
* selects which one (e.g. a test-only `config/test/babel.config.js`).
|
|
61
|
-
*
|
|
62
|
-
* templates, macros, and decorators,
|
|
63
|
-
*
|
|
64
|
-
*
|
|
61
|
+
* The project's babel config wins when it exists.
|
|
62
|
+
* `babel.configFile` selects which one (e.g. a test-only `config/test/babel.config.js`).
|
|
63
|
+
*
|
|
64
|
+
* Without one (libraries), `defaultBabelPlugins` covers TypeScript, templates, macros, and decorators,
|
|
65
|
+
* so no config file is required.
|
|
66
|
+
*
|
|
67
|
+
* Helpers are inlined in that case:
|
|
68
|
+
* projects without a babel config don't carry `@babel/runtime`.
|
|
65
69
|
*/
|
|
66
70
|
function babelOptions(nvpConfig: Config): BabelOptions {
|
|
67
71
|
const configFile = resolve(
|
|
@@ -83,9 +87,12 @@ function babelOptions(nvpConfig: Config): BabelOptions {
|
|
|
83
87
|
/**
|
|
84
88
|
* Additional opt-ins beyond maybeBabel's built-in list.
|
|
85
89
|
*
|
|
86
|
-
* These libraries ship code that still needs babel
|
|
87
|
-
*
|
|
88
|
-
*
|
|
90
|
+
* These libraries ship code that still needs babel:
|
|
91
|
+
* - ember-concurrency's decorators
|
|
92
|
+
* - ember-scoped-css transforms
|
|
93
|
+
* - ember-intl's formatMessage macro
|
|
94
|
+
*
|
|
95
|
+
* The `initializeRuntimeMacrosConfig` runtime call must also be compiled away.
|
|
89
96
|
*/
|
|
90
97
|
function babelFilter(nvpConfig: Config) {
|
|
91
98
|
return {
|
|
@@ -120,9 +127,10 @@ interface Config {
|
|
|
120
127
|
configFile?: string;
|
|
121
128
|
|
|
122
129
|
/**
|
|
123
|
-
* optional way to configure when babel is
|
|
124
|
-
*
|
|
125
|
-
*
|
|
130
|
+
* optional way to configure when babel is activated.
|
|
131
|
+
*
|
|
132
|
+
* by default, all transforming is oxc,
|
|
133
|
+
* except when babel is needed (for things not currently implemented in oxc)
|
|
126
134
|
*/
|
|
127
135
|
include?: {
|
|
128
136
|
/**
|
|
@@ -154,10 +162,12 @@ export function ember(nvpConfig: Config = {}) {
|
|
|
154
162
|
const filter = babelFilter(nvpConfig);
|
|
155
163
|
|
|
156
164
|
/*
|
|
157
|
-
* Plugins must be returned as top-level array entries
|
|
158
|
-
* config.plugins inside a config() hook.
|
|
159
|
-
*
|
|
160
|
-
*
|
|
165
|
+
* Plugins must be returned as top-level array entries,
|
|
166
|
+
* NOT pushed into config.plugins inside a config() hook.
|
|
167
|
+
*
|
|
168
|
+
* Vite 8 extracts user plugins *before* config hooks run,
|
|
169
|
+
* so anything added later is invisible to the plugin container
|
|
170
|
+
* (resolveId, load, etc. hooks never fire).
|
|
161
171
|
*/
|
|
162
172
|
return [
|
|
163
173
|
{
|
|
@@ -194,9 +204,8 @@ export function ember(nvpConfig: Config = {}) {
|
|
|
194
204
|
resolver({ rolldown: true }),
|
|
195
205
|
templateTag(),
|
|
196
206
|
|
|
197
|
-
// Libraries
|
|
198
|
-
//
|
|
199
|
-
// template compiler
|
|
207
|
+
// Libraries ship precompileTemplate calls and macros.
|
|
208
|
+
// Both must compile away here, with this app's template compiler.
|
|
200
209
|
maybeBabel({
|
|
201
210
|
...babel,
|
|
202
211
|
parallel: nvpConfig.babel?.parallel,
|
|
@@ -231,14 +240,12 @@ function applyConfig(viteConfig: ResolvedConfig, env: ConfigEnv, nvpConfig: Conf
|
|
|
231
240
|
}
|
|
232
241
|
|
|
233
242
|
function dev(viteConfig: ResolvedConfig, nvpConfig: Config) {
|
|
234
|
-
|
|
235
|
-
*
|
|
243
|
+
/**
|
|
236
244
|
* build config for tests
|
|
237
245
|
*
|
|
238
|
-
* NOTE: we can't minify
|
|
239
|
-
*
|
|
240
|
-
|
|
241
|
-
*************************************/
|
|
246
|
+
* NOTE: we can't minify.
|
|
247
|
+
* some tests check x.constructor.name, which changes when minified
|
|
248
|
+
*/
|
|
242
249
|
Object.assign(viteConfig.build, {
|
|
243
250
|
sourcemap: true,
|
|
244
251
|
cleanCssOptions: { sourceMap: true },
|
|
@@ -333,7 +340,8 @@ function prod(viteConfig: ResolvedConfig, nvpConfig: Config) {
|
|
|
333
340
|
minify: true,
|
|
334
341
|
cleanDir: true,
|
|
335
342
|
/**
|
|
336
|
-
*
|
|
343
|
+
* Needed due to how we manage module state.
|
|
344
|
+
*
|
|
337
345
|
* This can create waterfalls when too much top-level await is used.
|
|
338
346
|
*/
|
|
339
347
|
strictExecutionOrder: true,
|
|
@@ -342,10 +350,10 @@ function prod(viteConfig: ResolvedConfig, nvpConfig: Config) {
|
|
|
342
350
|
*/
|
|
343
351
|
codeSplitting: {
|
|
344
352
|
/**
|
|
345
|
-
* Kind of a shame this isn't automatic based on dynamic import usage
|
|
346
|
-
*
|
|
347
|
-
*
|
|
348
|
-
* rather than rely on automatic optimizations based on import/module usage
|
|
353
|
+
* Kind of a shame this isn't automatic based on dynamic import usage in vite8.
|
|
354
|
+
*
|
|
355
|
+
* This forces us to know every potential problem area of the app,
|
|
356
|
+
* rather than rely on automatic optimizations based on import/module usage.
|
|
349
357
|
*/
|
|
350
358
|
groups: [...(nvpConfig?.production?.codeSplittingGroups ?? [])],
|
|
351
359
|
},
|
package/src/test-html.ts
CHANGED
|
@@ -3,10 +3,10 @@ import { join } from "node:path";
|
|
|
3
3
|
import type { ViteDevServer } from "vite";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Everything a QUnit + testem run needs, with no project-specific
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* co-located `*-test` modules under src
|
|
6
|
+
* Everything a QUnit + testem run needs, with no project-specific references.
|
|
7
|
+
*
|
|
8
|
+
* - root-relative specifiers keep it independent of where the project keeps its files
|
|
9
|
+
* - the globs pick up tests/** as well as co-located `*-test` modules under src/**
|
|
10
10
|
*/
|
|
11
11
|
const DEFAULT_TEST_HTML = `<!doctype html>
|
|
12
12
|
<html>
|
|
@@ -39,14 +39,16 @@ const DEFAULT_TEST_HTML = `<!doctype html>
|
|
|
39
39
|
`;
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
|
-
* Lets a project run its tests without maintaining a tests/index.html
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* `
|
|
47
|
-
*
|
|
42
|
+
* Lets a project run its tests without maintaining a tests/index.html.
|
|
43
|
+
*
|
|
44
|
+
* Whenever that file is absent, this plugin answers for it:
|
|
45
|
+
* - `load` supplies the html to the build
|
|
46
|
+
* (so `tests/index.html` still lands in dist for testem)
|
|
47
|
+
* - the dev-server middleware serves it, through `transformIndexHtml`,
|
|
48
|
+
* so the html goes through the same pipeline as an on-disk file
|
|
48
49
|
*
|
|
49
|
-
* A tests/index.html on disk always wins
|
|
50
|
+
* A tests/index.html on disk always wins.
|
|
51
|
+
* Every hook here defers to it.
|
|
50
52
|
*/
|
|
51
53
|
export function testHtml() {
|
|
52
54
|
const htmlPath = join(process.cwd(), "tests", "index.html");
|