Registry / testing / babel-plugin-qunit-lazy-imports

babel-plugin-qunit-lazy-imports

JSON →
library1.2.0jsnpmunverified

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.

npm install babel-plugin-qunit-lazy-imports
INSTALL
IMPORT
SIG · BABEL-PLUGIN-QUNIT
B
babel-plugin-qunit-lazy-imports
testingjavascriptv1.2.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
module.exports = { plugins: [ ['module:babel-plugin-qunit-lazy-imports', { startsWith: ['my-app/'] }] ] };
plugins: [['babel-plugin-qunit-lazy-imports', ...]]
Use 'module:' prefix when using babel.config.js in Node.js; not needed in .babelrc or when using require directly.
default
const plugin = require('babel-plugin-qunit-lazy-imports');
CommonJS require works; no default import in ESM because the plugin does not export a named symbol.
plugin options
[ 'module:babel-plugin-qunit-lazy-imports', { startsWith: ['my-app/'], matches: [/.*\.lazy\..*/] } ]
{ "plugins": [ ["babel-plugin-qunit-lazy-imports", { startsWith: 'my-app/' }] ] }
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.

Shows basic setup with babel.config.js and example transformation of imports into lazy beforeEach imports.

// Install: npm add babel-plugin-qunit-lazy-imports --save-dev // babel.config.js module.exports = { plugins: [ [ 'module:babel-plugin-qunit-lazy-imports', { // Transform imports starting with 'my-app/' into lazy imports startsWith: ['my-app/'], // Also match any import matching regex (optional) matches: [/.*\.lazy\..*/], }, ], ], }; // Before transformation: // import { foo } from 'my-app/foo'; // import { bar } from 'some-other-lib'; // import { baz } from './baz.lazy'; // After transformation: // let foo, bar, baz; // module('...', function(hooks) { // hooks.beforeEach(async function() { // const mod1 = await import('my-app/foo'); // foo = mod1.foo; // const mod2 = await import('./baz.lazy'); // baz = mod2.baz; // }); // }); // Note: only imports matching startsWith or matches are transformed
Debug
Known issues
breakingOption 'startsWith' must be an array of strings; passing a single string causes runtime error.
fix
Use an array: startsWith: ['my-app/'] instead of startsWith: 'my-app/'
affects: >=1.0.0
gotchaPlugin only transforms imports that match startsWith or matches patterns; all other imports remain as static imports, which may cause unexpected synchronous loading.
fix
Ensure all imports you want to be lazy are covered by the patterns; add additional patterns as needed.
affects: >=1.0.0
gotchaLazy 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.
fix
Consider splitting test files with different suites into separate files, or manually manage lazy imports.
affects: >=1.0.0
deprecatedv1.0.0 initial release uses 'module:' prefix which is not compatible with some Babel configurations; no actual deprecation yet.
fix
Use 'module:babel-plugin-qunit-lazy-imports' in babel.config.js; for .babelrc, omit the 'module:' prefix.
affects: 1.0.0
Errors
Common errors & fixes
Cannot find module 'babel-plugin-qunit-lazy-imports'
Package not installed or not in node_modules.
fix
Run: npm add babel-plugin-qunit-lazy-imports --save-dev
Error: [BABEL] unknown: Plugin module:babel-plugin-qunit-lazy-imports requires @babel/core@^7.0.0 but was loaded with @babel/core@6.x.
Incompatible @babel/core version.
fix
Upgrade @babel/core to ^7.0.0: npm upgrade @babel/core
TypeError: startsWith.filter is not a function
startsWith option is not an array.
fix
Change startsWith to an array, e.g., startsWith: ['my-app/']
Upgrade
Version history
1.2.0latest on npm
Audit
Dependencies
@babel/corerequiredRequired as a peer dependency for Babel plugin API
Agent activity
24 hits · last 30 days
node
22
OpenAI (training)
1
Resources
babel-plugin-qunit-lazy-imports — npm install babel-plugin-qunit-lazy-imports · libregistry