Karma preprocessor for converting ES modules to AMD in RequireJS projects. Uses requirejs-esm-preprocessor.
module.exports = config => config.set({
preprocessors: {
'src/**/*.js': ['requirejs-esm']
},
requirejsEsmPreprocessor: {
isScript: path => !path.includes('/test/'),
sourceMap: true
}
})This module can be installed in your project using NPM, PNPM or Yarn. Make sure, that you use Node.js version 14 or newer.
npm i -D karma-requirejs-esm-preprocessor
pnpm i -D karma-requirejs-esm-preprocessor
yarn add karma-requirejs-esm-preprocessorisScript(path: string): booleanAllows further filtering the files before passing them to the preprocessor. If the patterns are inconvenient to specify what files should be preprocessed, a simple pattern can be used to capture all files and the final filtering be done by isScript returning true only for the paths to files which need preprocessing. The default is undefined - no extra filtering.
useStrict: booleanControls inserting "use strict" expression to the AMD code output. ESM modules are parsed in the strict mode by default, while AMD modules need the "use strict" statement. You can set this flag to false to relax the parse mode of the output AMD modules. The default is true.
sourceMap: booleanEnables an inline source map in the preprocessed output to support debugging in the browser. The default is true.
onBeforeTransform, onAfterTransform, onBeforeUpdate, onAfterUpdateESM transformation and AMD update callbacks.
In lieu of a formal styleguide, take care to maintain the existing coding style. Lint and test your code.
Copyright (c) 2022-2025 Ferdinand Prantl
Licensed under the MIT license.