{"id":19129,"library":"babel-plugin-qunit-lazy-imports","title":"babel-plugin-qunit-lazy-imports","description":"A Babel plugin that transforms ES module imports in QUnit test files into lazy imports inside beforeEach hooks, enabling on-demand loading of test dependencies. Current stable version is 1.2.0. Released as needed on GitHub by NullVoxPopuli. Key differentiator: designed for Vite-based QUnit projects to reduce initial bundle size by deferring module loading, with support for include/exclude patterns via startsWith and matches options. Requires @babel/core as a peer dependency and Node.js ^20.11 or >=22. Minimal plugin with no runtime dependencies, focused solely on QUnit test transformation.","status":"active","version":"1.2.0","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/NullVoxPopuli/babel-plugin-qunit-lazy-imports","tags":["javascript","babel","plugin","qunit","lazy","imports","testing"],"install":[{"cmd":"npm install babel-plugin-qunit-lazy-imports","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-qunit-lazy-imports","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-qunit-lazy-imports","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required as a peer dependency for Babel plugin API","package":"@babel/core","optional":false}],"imports":[{"note":"Use 'module:' prefix when using babel.config.js in Node.js; not needed in .babelrc or when using require directly.","wrong":"plugins: [['babel-plugin-qunit-lazy-imports', ...]]","symbol":"default","correct":"module.exports = {\n  plugins: [\n    ['module:babel-plugin-qunit-lazy-imports', { startsWith: ['my-app/'] }]\n  ]\n};"},{"note":"CommonJS require works; no default import in ESM because the plugin does not export a named symbol.","wrong":"","symbol":"default","correct":"const plugin = require('babel-plugin-qunit-lazy-imports');"},{"note":"startsWith must be an array of strings; matches must be an array of RegExp. Both options are optional but at least one must be provided.","wrong":"{\n  \"plugins\": [\n    [\"babel-plugin-qunit-lazy-imports\", { startsWith: 'my-app/' }]\n  ]\n}","symbol":"plugin options","correct":"[\n  'module:babel-plugin-qunit-lazy-imports',\n  { startsWith: ['my-app/'], matches: [/.*\\.lazy\\..*/] }\n]"}],"quickstart":{"code":"// Install: npm add babel-plugin-qunit-lazy-imports --save-dev\n\n// babel.config.js\nmodule.exports = {\n  plugins: [\n    [\n      'module:babel-plugin-qunit-lazy-imports',\n      {\n        // Transform imports starting with 'my-app/' into lazy imports\n        startsWith: ['my-app/'],\n        // Also match any import matching regex (optional)\n        matches: [/.*\\.lazy\\..*/],\n      },\n    ],\n  ],\n};\n\n// Before transformation:\n// import { foo } from 'my-app/foo';\n// import { bar } from 'some-other-lib';\n// import { baz } from './baz.lazy';\n\n// After transformation:\n// let foo, bar, baz;\n// module('...', function(hooks) {\n//   hooks.beforeEach(async function() {\n//     const mod1 = await import('my-app/foo');\n//     foo = mod1.foo;\n//     const mod2 = await import('./baz.lazy');\n//     baz = mod2.baz;\n//   });\n// });\n// Note: only imports matching startsWith or matches are transformed","lang":"javascript","description":"Shows basic setup with babel.config.js and example transformation of imports into lazy beforeEach imports."},"warnings":[{"fix":"Use an array: startsWith: ['my-app/'] instead of startsWith: 'my-app/'","message":"Option 'startsWith' must be an array of strings; passing a single string causes runtime error.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Ensure all imports you want to be lazy are covered by the patterns; add additional patterns as needed.","message":"Plugin only transforms imports that match startsWith or matches patterns; all other imports remain as static imports, which may cause unexpected synchronous loading.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Consider splitting test files with different suites into separate files, or manually manage lazy imports.","message":"Lazy imports are hoisted to a single beforeEach hook per module (suite). If your test file has multiple module() calls, imports from different suites may be loaded before the suite runs due to hoisting.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use 'module:babel-plugin-qunit-lazy-imports' in babel.config.js; for .babelrc, omit the 'module:' prefix.","message":"v1.0.0 initial release uses 'module:' prefix which is not compatible with some Babel configurations; no actual deprecation yet.","severity":"deprecated","affected_versions":"1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run: npm add babel-plugin-qunit-lazy-imports --save-dev","cause":"Package not installed or not in node_modules.","error":"Cannot find module 'babel-plugin-qunit-lazy-imports'"},{"fix":"Upgrade @babel/core to ^7.0.0: npm upgrade @babel/core","cause":"Incompatible @babel/core version.","error":"Error: [BABEL] unknown: Plugin module:babel-plugin-qunit-lazy-imports requires @babel/core@^7.0.0 but was loaded with @babel/core@6.x."},{"fix":"Change startsWith to an array, e.g., startsWith: ['my-app/']","cause":"startsWith option is not an array.","error":"TypeError: startsWith.filter is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}