@nullvoxpopuli/ember-vite 2.3.0 → 2.3.1

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.
@@ -0,0 +1,68 @@
1
+ import { maybeBabel } from "@nullvoxpopuli/ember-build-tooling-utils";
2
+ import { Plugin } from "vite";
3
+ //#region src/ember.d.ts
4
+ interface Config {
5
+ babel?: {
6
+ /**
7
+ * when babel runs, do so in parallel across many cores.
8
+ *
9
+ * defaults to true when the project has a babel config file.
10
+ * Without one, babel stays in the main thread:
11
+ * the default plugins carry functions,
12
+ * and a worker thread cannot receive functions.
13
+ */
14
+ parallel?: false;
15
+ /**
16
+ * which babel config file to use for this build, relative to the
17
+ * project root. defaults to "./babel.config.js".
18
+ *
19
+ * useful when the root babel config belongs to another pipeline
20
+ * (e.g. a library's publish build) and the vite build needs its own,
21
+ * such as "./config/test/babel.config.js".
22
+ */
23
+ configFile?: string;
24
+ /**
25
+ * optional way to configure when babel is activated.
26
+ *
27
+ * by default, all transforming is oxc,
28
+ * except when babel is needed (for things not currently implemented in oxc)
29
+ */
30
+ include?: {
31
+ /**
32
+ * if a file imports from anything in this array, use babel instead of
33
+ * oxc for that file.
34
+ *
35
+ * For example: ['my-babel-only-library'],
36
+ */
37
+ whenImporting?: (string | "ember-concurrency" | "ember-scoped-css")[];
38
+ /**
39
+ * if a file's source contains any of these strings,
40
+ * or matches any of these regular expressions,
41
+ * use babel instead of oxc for that file.
42
+ *
43
+ * Use this for babel plugins that look for a code pattern rather than
44
+ * an import.
45
+ *
46
+ * For example: [/\.register\(/],
47
+ */
48
+ whenMatching?: (string | RegExp)[];
49
+ };
50
+ };
51
+ /**
52
+ * optional production configs
53
+ */
54
+ production?: {
55
+ /**
56
+ * optional configuration of codeSplitting.groups
57
+ * in the vite config.
58
+ *
59
+ * Docs here:
60
+ * https://rolldown.rs/reference/OutputOptions.codeSplitting#groups
61
+ */
62
+ codeSplittingGroups: any[];
63
+ };
64
+ }
65
+ declare function ember(nvpConfig?: Config): Plugin[];
66
+ //#endregion
67
+ export { ember, maybeBabel };
68
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/ember.ts"],"mappings":";;;UAmOU;EACR;;;;;;;;;IASE;;;;;;;;;IAUA;;;;;;;IAQA;;;;;;;MAOE;;;;;;;;;;;MAYA,yBAAyB;;;;;;EAM7B;;;;;;;;IAQE;;;iBAIY,MAAM,YAAW,SAAc"}
package/dist/index.js CHANGED
@@ -436,3 +436,5 @@ groups: [...nvpConfig?.production?.codeSplittingGroups ?? []] }
436
436
  }
437
437
  //#endregion
438
438
  export { ember, maybeBabel };
439
+
440
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["embroiderEmber","maybeBabel"],"sources":["../src/test-html.ts","../src/ember.ts"],"sourcesContent":["import { existsSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport type { ViteDevServer } from \"vite\";\n\n/**\n * Everything a QUnit + testem run needs, with no project-specific references.\n *\n * - root-relative specifiers keep it independent of where the project keeps its files\n * - the globs pick up tests/** as well as co-located `*-test` modules under src/**\n */\nconst DEFAULT_TEST_HTML = `<!doctype html>\n<html>\n <head>\n <meta charset=\"utf-8\" />\n <title>Tests</title>\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n </head>\n <body>\n <div id=\"qunit\"></div>\n <div id=\"qunit-fixture\">\n <div id=\"ember-testing-container\">\n <div id=\"ember-testing\"></div>\n </div>\n </div>\n\n <script src=\"/testem.js\" integrity=\"\" data-embroider-ignore></script>\n <script type=\"module\">\n import \"ember-testing\";\n </script>\n\n <script type=\"module\">\n import { start } from \"/tests/test-helper\";\n import.meta.glob(\"/tests/**/*.{js,ts,gjs,gts}\", { eager: true });\n import.meta.glob(\"/src/**/*-test.{js,ts,gjs,gts}\", { eager: true });\n start();\n </script>\n </body>\n</html>\n`;\n\n/**\n * Lets a project run its tests without maintaining a tests/index.html.\n *\n * Whenever that file is absent, this plugin answers for it:\n * - `load` supplies the html to the build\n * (so `tests/index.html` still lands in dist for testem)\n * - the dev-server middleware serves it, through `transformIndexHtml`,\n * so the html goes through the same pipeline as an on-disk file\n *\n * A tests/index.html on disk always wins.\n * Every hook here defers to it.\n */\nexport function testHtml() {\n const htmlPath = join(process.cwd(), \"tests\", \"index.html\");\n\n return {\n name: \"ember:default-test-html\",\n\n resolveId(id: string) {\n if (id === htmlPath && !existsSync(htmlPath)) {\n return id;\n }\n },\n\n load(id: string) {\n if (id === htmlPath && !existsSync(htmlPath)) {\n return DEFAULT_TEST_HTML;\n }\n },\n\n configureServer(server: ViteDevServer) {\n server.middlewares.use(async (req, res, next) => {\n if (existsSync(htmlPath)) return next();\n\n const url = (req.url ?? \"\").split(\"?\")[0];\n\n if (url !== \"/tests\" && url !== \"/tests/\" && url !== \"/tests/index.html\") {\n return next();\n }\n\n const html = await server.transformIndexHtml(\"/tests/index.html\", DEFAULT_TEST_HTML);\n\n res.setHeader(\"Content-Type\", \"text/html\");\n res.end(html);\n });\n },\n };\n}\n","import { buildMacros } from \"@embroider/macros/babel\";\nimport { ember as embroiderEmber, extensions, resolver, templateTag } from \"@embroider/vite\";\nimport type { PluginItem } from \"@babel/core\";\nimport { existsSync, readFileSync } from \"node:fs\";\nimport { join, resolve } from \"node:path\";\nimport type { ConfigEnv, ConfigPluginContext, Plugin, ResolvedConfig, UserConfig } from \"vite\";\n\nimport { maybeBabel } from \"@nullvoxpopuli/ember-build-tooling-utils\";\n\nimport { testHtml } from \"./test-html.ts\";\n\nconst EMBER_CONFIG = \"vite-plugin-ember-config\";\n\ntype ConfigHook = (\n this: ConfigPluginContext,\n config: UserConfig,\n env: ConfigEnv,\n) => Promise<unknown> | unknown;\n\n/**\n * `@embroider/vite` does not export its config hook on its own.\n *\n * The position of the plugin in the list changes between releases,\n * so the name is the only stable way to find it.\n */\nfunction findEmberConfig(): ConfigHook {\n for (const plugin of embroiderEmber()) {\n if (plugin.name !== EMBER_CONFIG) continue;\n\n const hook = plugin.config;\n const handler = typeof hook === \"function\" ? hook : hook?.handler;\n\n if (handler) return handler as ConfigHook;\n }\n\n throw new Error(\n `@embroider/vite has no \"${EMBER_CONFIG}\" plugin with a config hook. ` +\n `This version of @embroider/vite is not supported by @nullvoxpopuli/ember-vite.`,\n );\n}\n\nconst emberConfig = findEmberConfig();\n\nconst cwd = process.cwd();\nfunction absolutePath(relativePath: string) {\n return join(cwd, relativePath);\n}\n\n/**\n * Everything a project without its own babel config needs:\n *\n * - TypeScript stripping\n * - template compilation, to the wire format\n * (vite serves and bundles for the project's own ember-source,\n * so the final compile happens here)\n * - build macros, evaluated at build time\n * - decorator-transforms, with its runtime left as a bare specifier\n * so it resolves from the project\n * (the project depends on `decorator-transforms`)\n *\n * The plugins are named, not imported.\n * babel resolves them from the project, which carries them as its own dependencies.\n *\n * The macros take development mode from the vite mode.\n * `buildMacros` reads NODE_ENV, but vite sets NODE_ENV\n * only after the config hooks run.\n */\nfunction defaultBabelPlugins(mode: string): PluginItem[] {\n const macros = buildMacros({\n configure(config) {\n if (isDev(mode)) {\n config.enablePackageDevelopment(process.cwd());\n config.enableRuntimeMode();\n }\n },\n });\n\n return [\n [\n \"@babel/plugin-transform-typescript\",\n {\n allExtensions: true,\n onlyRemoveTypeImports: true,\n allowDeclareFields: true,\n },\n ],\n [\"babel-plugin-ember-template-compilation\", { transforms: [...macros.templateMacros] }],\n [\"module:decorator-transforms\", { runtime: { import: \"decorator-transforms/runtime-esm\" } }],\n ...macros.babelMacros,\n ];\n}\n\ntype BabelOptions =\n | { configFile: string }\n | {\n configFile: false;\n plugins: ReturnType<typeof defaultBabelPlugins>;\n };\n\n/**\n * Other names babel loads a project config from.\n */\nconst OTHER_BABEL_CONFIGS = [\n \"babel.config.mjs\",\n \"babel.config.cjs\",\n \"babel.config.cts\",\n \"babel.config.json\",\n];\n\n/**\n * A v2 addon. Its babel config is for publishing, so vite keeps the default plugins.\n */\nfunction isLibrary(): boolean {\n const manifestPath = join(process.cwd(), \"package.json\");\n\n if (!existsSync(manifestPath)) return false;\n\n return JSON.parse(readFileSync(manifestPath, \"utf-8\"))[\"ember-addon\"]?.type === \"addon\";\n}\n\n/**\n * The project's babel config wins when it exists.\n * `babel.configFile` selects which one (e.g. a test-only `config/test/babel.config.js`).\n *\n * Without one (libraries), `defaultBabelPlugins` covers TypeScript, templates, macros, and decorators,\n * so no config file is required.\n * Babel helpers are inlined in that case:\n * projects without a babel config don't carry `@babel/runtime`.\n *\n * An app whose config has another name would otherwise get the defaults without noticing,\n * so that is an error.\n */\nfunction babelOptions(nvpConfig: Config): BabelOptions {\n const configFile = resolve(\n join(process.cwd(), nvpConfig.babel?.configFile ?? \"./babel.config.js\"),\n );\n\n if (existsSync(configFile)) {\n return { configFile };\n }\n\n if (!nvpConfig.babel?.configFile && !isLibrary()) {\n const otherConfig = OTHER_BABEL_CONFIGS.find((name) => existsSync(join(process.cwd(), name)));\n\n if (otherConfig) {\n throw new Error(\n `@nullvoxpopuli/ember-vite reads babel.config.js, but this project has ${otherConfig}. ` +\n `Pass \\`ember({ babel: { configFile: \"./${otherConfig}\" } })\\` to use it.`,\n );\n }\n }\n\n /**\n * The config hook fills this list, once it knows the vite mode.\n * The babel plugins keep a reference to it, so they see the filled list.\n */\n return {\n configFile: false,\n plugins: [],\n };\n}\n\n/**\n * Libraries that ship code that still needs babel.\n * Each one adds to the filter only when the project depends on it,\n * so other projects do not pay for the check.\n *\n * - ember-concurrency's decorators\n * - ember-intl's formatMessage macro\n * - ember-qunit-nice-errors, which adds a message to each QUnit assertion\n * - ember-scoped-css transforms\n * - unplugin-icons, whose icon modules compile with `template()`.\n * Their ids have no file extension, so only the id matches them.\n */\nconst LIBRARY_FILTERS: Record<\n string,\n { imports?: string[]; code?: (string | RegExp)[]; ids?: RegExp[] }\n> = {\n \"ember-concurrency\": { imports: [\"ember-concurrency\"] },\n \"ember-intl\": {\n imports: [\"ember-intl/helpers/format-message\"],\n code: [/\\bintl\\.formatMessage\\b/],\n },\n \"ember-qunit-nice-errors\": { code: [/\\bassert\\.[a-zA-Z]+\\(/] },\n \"ember-scoped-css\": { imports: [\"ember-scoped-css\"] },\n \"unplugin-icons\": { ids: [/^~icons\\//] },\n};\n\nfunction projectDependencies(): Set<string> {\n const manifestPath = join(process.cwd(), \"package.json\");\n\n if (!existsSync(manifestPath)) return new Set();\n\n const manifest = JSON.parse(readFileSync(manifestPath, \"utf-8\"));\n\n return new Set(Object.keys({ ...manifest.dependencies, ...manifest.devDependencies }));\n}\n\n/**\n * Additional opt-ins beyond maybeBabel's built-in list.\n * The `initializeRuntimeMacrosConfig` runtime call must compile away in every project.\n */\nfunction babelFilter(nvpConfig: Config) {\n const imports: string[] = [];\n const code: (string | RegExp)[] = [\"initializeRuntimeMacrosConfig\"];\n const ids: RegExp[] = [];\n const dependencies = projectDependencies();\n\n for (const [name, filter] of Object.entries(LIBRARY_FILTERS)) {\n if (!dependencies.has(name)) continue;\n\n for (const specifier of filter.imports ?? []) imports.push(specifier);\n for (const pattern of filter.code ?? []) code.push(pattern);\n for (const pattern of filter.ids ?? []) ids.push(pattern);\n }\n\n for (const specifier of nvpConfig.babel?.include?.whenImporting ?? []) {\n imports.push(specifier);\n }\n\n for (const pattern of nvpConfig.babel?.include?.whenMatching ?? []) {\n code.push(pattern);\n }\n\n return { include: { imports, code, ids } };\n}\n\ninterface Config {\n babel?: {\n /**\n * when babel runs, do so in parallel across many cores.\n *\n * defaults to true when the project has a babel config file.\n * Without one, babel stays in the main thread:\n * the default plugins carry functions,\n * and a worker thread cannot receive functions.\n */\n parallel?: false;\n\n /**\n * which babel config file to use for this build, relative to the\n * project root. defaults to \"./babel.config.js\".\n *\n * useful when the root babel config belongs to another pipeline\n * (e.g. a library's publish build) and the vite build needs its own,\n * such as \"./config/test/babel.config.js\".\n */\n configFile?: string;\n\n /**\n * optional way to configure when babel is activated.\n *\n * by default, all transforming is oxc,\n * except when babel is needed (for things not currently implemented in oxc)\n */\n include?: {\n /**\n * if a file imports from anything in this array, use babel instead of\n * oxc for that file.\n *\n * For example: ['my-babel-only-library'],\n */\n whenImporting?: (string | \"ember-concurrency\" | \"ember-scoped-css\")[];\n\n /**\n * if a file's source contains any of these strings,\n * or matches any of these regular expressions,\n * use babel instead of oxc for that file.\n *\n * Use this for babel plugins that look for a code pattern rather than\n * an import.\n *\n * For example: [/\\.register\\(/],\n */\n whenMatching?: (string | RegExp)[];\n };\n };\n /**\n * optional production configs\n */\n production?: {\n /**\n * optional configuration of codeSplitting.groups\n * in the vite config.\n *\n * Docs here:\n * https://rolldown.rs/reference/OutputOptions.codeSplitting#groups\n */\n codeSplittingGroups: any[];\n };\n}\n\nexport function ember(nvpConfig: Config = {}): Plugin[] {\n const babel = babelOptions(nvpConfig);\n const filter = babelFilter(nvpConfig);\n const parallel = nvpConfig.babel?.parallel ?? babel.configFile !== false;\n\n /*\n * Plugins must be returned as top-level array entries,\n * NOT pushed into config.plugins inside a config() hook.\n *\n * Vite 8 extracts user plugins *before* config hooks run,\n * so anything added later is invisible to the plugin container\n * (resolveId, load, etc. hooks never fire).\n */\n return [\n {\n // no compat\n name: \"ember:nullvoxpopuli\",\n async config(this: ConfigPluginContext, viteConfig: any, env: ConfigEnv) {\n /**\n * Read before the config hooks below write their defaults into `viteConfig`,\n * and put back over them after `applyConfig`.\n */\n const project = projectConfig(viteConfig);\n\n /**\n * The hook reads the rolldown version from the plugin context,\n * and takes its esbuild path without it.\n */\n await emberConfig.call(this, viteConfig, env);\n\n applyPreviewPort(viteConfig);\n\n if (\"plugins\" in babel) {\n babel.plugins.length = 0;\n\n for (const plugin of defaultBabelPlugins(env.mode)) {\n babel.plugins.push(plugin);\n }\n }\n\n viteConfig.experimental ||= {};\n viteConfig.build ||= {};\n viteConfig.optimizeDeps ||= {};\n\n viteConfig.oxc = {\n // babel handles legacy decorators\n // decorator: {\n // legacy: true,\n // },\n };\n // config.experimental.bundledDev = true;\n viteConfig.experimental.nativeMagicString = true;\n delete viteConfig.esbuild;\n delete viteConfig.optimizeDeps.esbuildOptions;\n\n viteConfig.build.reportCompressedSize = false;\n viteConfig.build.extensions = extensions;\n viteConfig.optimizeDeps.extensions = [\".gjs\", \".gts\"];\n viteConfig.optimizeDeps.rolldownOptions ||= {};\n viteConfig.optimizeDeps.rolldownOptions.tsconfig = true;\n\n applyConfig(viteConfig, env, nvpConfig);\n keepProjectConfig(viteConfig, project);\n\n viteConfig.optimizeDeps.rolldownOptions.plugins = [\n ...project.optimizeDepsPlugins,\n resolver({ rolldown: true }),\n templateTag(),\n\n // Libraries ship precompileTemplate calls and macros.\n // Both must compile away here, with this app's template compiler.\n maybeBabel({\n ...babel,\n parallel,\n filter,\n }),\n ];\n },\n },\n resolver({ rolldown: true }),\n templateTag(),\n testHtml(),\n /**\n * maybeBabel returns a rolldown plugin.\n * Vite can depend on another rolldown version,\n * so the two Plugin types do not always match.\n */\n maybeBabel({\n ...babel,\n parallel,\n filter,\n }) as Plugin,\n ];\n}\n\n/**\n * What the project's own vite config sets, before any config hook changes it.\n *\n * What the config hooks here and in `@embroider/vite` set in `build`,\n * `build.rolldownOptions.output` and `build.rolldownOptions.optimization` are defaults:\n * a project that sets one, such as `build.sourcemap: \"hidden\"`\n * or `build.rolldownOptions.output.strictExecutionOrder: false`, keeps its value.\n * The project's own optimizeDeps plugins run before the ones this plugin adds.\n */\nfunction projectConfig(viteConfig: UserConfig) {\n const build = viteConfig.build ?? {};\n const output = build.rolldownOptions?.output;\n const optimizeDepsPlugins = viteConfig.optimizeDeps?.rolldownOptions?.plugins;\n\n return {\n /**\n * Vite 8 makes `build.rollupOptions` an accessor for `build.rolldownOptions`.\n * Neither is put back: that would replace the object the config hooks fill in.\n */\n build: setValues(build, [\"rolldownOptions\", \"rollupOptions\"]),\n output: Array.isArray(output) ? {} : setValues(output),\n optimization: setValues(build.rolldownOptions?.optimization),\n optimizeDepsPlugins: Array.isArray(optimizeDepsPlugins) ? [...optimizeDepsPlugins] : [],\n };\n}\n\n/**\n * The entries that have a value.\n * A project that sets `sourcemap: undefined` gets the default, as if it had not set it.\n */\nfunction setValues(object: object | undefined, skip: string[] = []) {\n return Object.fromEntries(\n Object.entries(object ?? {}).filter(\n ([key, value]) => value !== undefined && !skip.includes(key),\n ),\n );\n}\n\nfunction keepProjectConfig(viteConfig: UserConfig, project: ReturnType<typeof projectConfig>) {\n Object.assign(viteConfig.build!, project.build);\n\n const { output, optimization } = viteConfig.build!.rolldownOptions ?? {};\n\n if (output && !Array.isArray(output)) Object.assign(output, project.output);\n if (optimization) Object.assign(optimization, project.optimization);\n}\n\n/**\n * `vite preview` serves the build on `$PORT`, the port that hosts and CI give,\n * or on 4200, the port of the dev server.\n * Vite itself reads no `$PORT`, and `@embroider/vite` only sets the dev server's port.\n * A port in the project's own vite config wins.\n */\nfunction applyPreviewPort(viteConfig: UserConfig) {\n viteConfig.preview ||= {};\n viteConfig.preview.port ??= Number(process.env.PORT) || 4200;\n}\n\nconst MODE_DEV = \"development\";\n\nfunction isDev(mode: string) {\n return mode === MODE_DEV;\n}\n\nfunction applyConfig(viteConfig: ResolvedConfig, env: ConfigEnv, nvpConfig: Config) {\n if (isDev(env.mode)) {\n return dev(viteConfig, nvpConfig);\n }\n\n return prod(viteConfig, nvpConfig);\n}\n\nfunction dev(viteConfig: ResolvedConfig, nvpConfig: Config) {\n /**\n * build config for tests\n *\n * NOTE: we can't minify.\n * some tests check x.constructor.name, which changes when minified\n */\n Object.assign(viteConfig.build, {\n sourcemap: true,\n cleanCssOptions: { sourceMap: true },\n minify: false,\n cssMinify: false,\n });\n\n viteConfig.build.rolldownOptions ||= {};\n viteConfig.build.rolldownOptions.input ||= {};\n viteConfig.build.rolldownOptions.output ||= {};\n\n // libraries don't, by default, have a \"demo app\" entrypoint\n if (existsSync(\"./index.html\")) {\n Object.assign(viteConfig.build.rolldownOptions.input, {\n main: absolutePath(\"./index.html\"),\n });\n }\n\n if (existsSync(\"./tests/index.html\")) {\n Object.assign(viteConfig.build.rolldownOptions.input, {\n tests: absolutePath(\"./tests/index.html\"),\n });\n } else if (existsSync(\"./tests.html\")) {\n Object.assign(viteConfig.build.rolldownOptions.input, {\n tests: absolutePath(\"./tests.html\"),\n });\n } else if (existsSync(\"./tests\")) {\n // no html of its own: the default-test-html plugin answers for\n // tests/index.html\n Object.assign(viteConfig.build.rolldownOptions.input, {\n tests: absolutePath(\"./tests/index.html\"),\n });\n }\n\n Object.assign(viteConfig.build.rolldownOptions.output, {\n cleanDir: true,\n strictExecutionOrder: true,\n codeSplitting: {\n groups: [\n // our \"test\" product-land code happens to not match this pattern\n { name: \"tests\", test: /[.-]test\\.g?(j|t)s/, priority: 10 },\n {\n name: \"common\",\n minShareCount: 10,\n minSize: 10000,\n maxSize: 1 * 1024 * 1024, // 1~ish MB\n priority: 9,\n },\n {\n name: \"uncommon\",\n minShareCount: 2,\n minSize: 10000,\n maxSize: 1 * 1024 * 1024, // 1~ish MB\n priority: 5,\n },\n ],\n },\n });\n\n return;\n}\nfunction prod(viteConfig: ResolvedConfig, nvpConfig: Config) {\n Object.assign(viteConfig.build, {\n minify: \"oxc\",\n sourcemap: true,\n reportCompressedSize: false,\n modulePreload: true,\n cleanCssOptions: { sourceMap: true },\n });\n\n viteConfig.build.rolldownOptions ||= {};\n viteConfig.build.rolldownOptions.input ||= {};\n viteConfig.build.rolldownOptions.optimization ||= {};\n viteConfig.build.rolldownOptions.output ||= {};\n\n // libraries don't, by default, have a \"demo app\" entrypoint\n if (existsSync(\"./index.html\")) {\n Object.assign(viteConfig.build.rolldownOptions.input, {\n main: absolutePath(\"./index.html\"),\n });\n }\n\n Object.assign(viteConfig.build.rolldownOptions.optimization, {\n inlineConst: {\n mode: \"smart\",\n pass: 3,\n },\n pifeForModuleWrappers: true,\n });\n\n Object.assign(viteConfig.build.rolldownOptions.output, {\n minify: true,\n cleanDir: true,\n /**\n * Needed due to how we manage module state.\n *\n * This can create waterfalls when too much top-level await is used.\n */\n strictExecutionOrder: true,\n /**\n * Code splitting currently makes things worse\n */\n codeSplitting: {\n /**\n * Kind of a shame this isn't automatic based on dynamic import usage in vite8.\n *\n * This forces us to know every potential problem area of the app,\n * rather than rely on automatic optimizations based on import/module usage.\n */\n groups: [...(nvpConfig?.production?.codeSplittingGroups ?? [])],\n },\n });\n}\n"],"mappings":";;;;;;;;;;;;AAUA,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0C1B,SAAgB,WAAW;CACzB,MAAM,WAAW,KAAK,QAAQ,IAAI,GAAG,SAAS,YAAY;CAE1D,OAAO;EACL,MAAM;EAEN,UAAU,IAAY;GACpB,IAAI,OAAO,YAAY,CAAC,WAAW,QAAQ,GACzC,OAAO;EAEX;EAEA,KAAK,IAAY;GACf,IAAI,OAAO,YAAY,CAAC,WAAW,QAAQ,GACzC,OAAO;EAEX;EAEA,gBAAgB,QAAuB;GACrC,OAAO,YAAY,IAAI,OAAO,KAAK,KAAK,SAAS;IAC/C,IAAI,WAAW,QAAQ,GAAG,OAAO,KAAK;IAEtC,MAAM,OAAO,IAAI,OAAO,GAAA,CAAI,MAAM,GAAG,CAAC,CAAC;IAEvC,IAAI,QAAQ,YAAY,QAAQ,aAAa,QAAQ,qBACnD,OAAO,KAAK;IAGd,MAAM,OAAO,MAAM,OAAO,mBAAmB,qBAAqB,iBAAiB;IAEnF,IAAI,UAAU,gBAAgB,WAAW;IACzC,IAAI,IAAI,IAAI;GACd,CAAC;EACH;CACF;AACF;;;AC5EA,MAAM,eAAe;;;;;;;AAcrB,SAAS,kBAA8B;CACrC,KAAK,MAAM,UAAUA,QAAe,GAAG;EACrC,IAAI,OAAO,SAAS,cAAc;EAElC,MAAM,OAAO,OAAO;EACpB,MAAM,UAAU,OAAO,SAAS,aAAa,OAAO,MAAM;EAE1D,IAAI,SAAS,OAAO;CACtB;CAEA,MAAM,IAAI,MACR,2BAA2B,aAAa,4GAE1C;AACF;AAEA,MAAM,cAAc,gBAAgB;A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AW,CAAC;CAG7C,IAAI,WAAW,cAAc,GAC3B,OAAO,OAAO,WAAW,MAAM,gBAAgB,OAAO,EACpD,MAAM,aAAa,cAAc,EACnC,CAAC;CAGH,OAAO,OAAO,WAAW,MAAM,gBAAgB,cAAc;EAC3D,aAAa;GACX,MAAM;GACN,MAAM;EACR;EACA,uBAAuB;CACzB,CAAC;CAED,OAAO,OAAO,WAAW,MAAM,gBAAgB,QAAQ;EACrD,QAAQ;EACR,UAAU;;;;;;EAMV,sBAAsB;;;;EAItB,eAAe;;;;;;;AAOb,QAAQ,CAAC,GAAI,WAAW,YAAY,uBAAuB,CAAC,CAAE,EAChE;CACF,CAAC;AACH"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nullvoxpopuli/ember-vite",
3
- "version": "2.3.0",
3
+ "version": "2.3.1",
4
4
  "description": "Meta plugin for ember projects focusing on speed.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -21,7 +21,7 @@
21
21
  "@embroider/core": "^4.6.9",
22
22
  "@embroider/macros": "^1.21.3",
23
23
  "@embroider/vite": "^1.7.15",
24
- "@nullvoxpopuli/ember-build-tooling-utils": "2.1.0"
24
+ "@nullvoxpopuli/ember-build-tooling-utils": "2.1.1"
25
25
  },
26
26
  "engines": {
27
27
  "node": ">= 24"
@@ -31,11 +31,21 @@
31
31
  "@rolldown/pluginutils": "^1.0.1",
32
32
  "babel-plugin-ember-template-compilation": "^4.0.1",
33
33
  "decorator-transforms": "^2.4.0",
34
- "rolldown": "^1.1.2",
34
+ "tsdown": "^0.22.9",
35
35
  "typescript": "^6.0.3",
36
36
  "vite": "^8.0.14"
37
37
  },
38
+ "peerDependencies": {
39
+ "vite": ">= 8"
40
+ },
38
41
  "scripts": {
39
- "build": "rolldown --config"
40
- }
42
+ "build": "tsdown"
43
+ },
44
+ "exports": {
45
+ ".": {
46
+ "types": "./dist/index.d.ts",
47
+ "default": "./dist/index.js"
48
+ }
49
+ },
50
+ "types": "dist/index.d.ts"
41
51
  }
package/src/ember.ts CHANGED
@@ -3,7 +3,7 @@ import { ember as embroiderEmber, extensions, resolver, templateTag } from "@emb
3
3
  import type { PluginItem } from "@babel/core";
4
4
  import { existsSync, readFileSync } from "node:fs";
5
5
  import { join, resolve } from "node:path";
6
- import type { ConfigEnv, ConfigPluginContext, ResolvedConfig, UserConfig } from "vite";
6
+ import type { ConfigEnv, ConfigPluginContext, Plugin, ResolvedConfig, UserConfig } from "vite";
7
7
 
8
8
  import { maybeBabel } from "@nullvoxpopuli/ember-build-tooling-utils";
9
9
 
@@ -290,7 +290,7 @@ interface Config {
290
290
  };
291
291
  }
292
292
 
293
- export function ember(nvpConfig: Config = {}) {
293
+ export function ember(nvpConfig: Config = {}): Plugin[] {
294
294
  const babel = babelOptions(nvpConfig);
295
295
  const filter = babelFilter(nvpConfig);
296
296
  const parallel = nvpConfig.babel?.parallel ?? babel.configFile !== false;
@@ -372,11 +372,16 @@ export function ember(nvpConfig: Config = {}) {
372
372
  resolver({ rolldown: true }),
373
373
  templateTag(),
374
374
  testHtml(),
375
+ /**
376
+ * maybeBabel returns a rolldown plugin.
377
+ * Vite can depend on another rolldown version,
378
+ * so the two Plugin types do not always match.
379
+ */
375
380
  maybeBabel({
376
381
  ...babel,
377
382
  parallel,
378
383
  filter,
379
- }),
384
+ }) as Plugin,
380
385
  ];
381
386
  }
382
387
 
@@ -0,0 +1,6 @@
1
+ import { defineConfig } from "tsdown";
2
+
3
+ export default defineConfig({
4
+ entry: "index.ts",
5
+ outExtensions: () => ({ js: ".js", dts: ".d.ts" }),
6
+ });
@@ -1,18 +0,0 @@
1
- import { defineConfig } from "rolldown";
2
-
3
- import manifest from "./package.json" with { type: "json" };
4
-
5
- const deps = Object.keys(manifest.dependencies || {});
6
-
7
- export default defineConfig({
8
- input: "index.ts",
9
- output: {
10
- format: "esm",
11
- file: "dist/index.js",
12
- codeSplitting: false,
13
- },
14
- external(id) {
15
- if (id.startsWith("node:")) return true;
16
- if (deps.some((dep) => id.startsWith(dep))) return true;
17
- },
18
- });