For Node.js build pipelines that output CommonJS bundles (webpack with
output.libraryTarget: 'commonjs', Rollup with CJS output, or
any toolchain that uses require()). The library ships as
taga11y.cjs and is loaded via require().
CommonJS is typically used in server-side bundling or legacy toolchains.
The <script> below uses a Node-style require()
shim so it works in the browser for demonstration. In production, you would
run this through your bundler which resolves require('taga11y')
to dist/taga11y.cjs.
// 1. Install via npm
// npm install taga11y
// 2. Require in your CommonJS source (webpack, Rollup CJS, etc.)
const { Taga11y } = require('taga11y');
require('taga11y/dist/taga11y.css');
// 3. Instantiate
const widget = new Taga11y(inputEl, {
suggestions: ['Apple', 'Banana', 'Cherry'],
});
// The package.json "main" field points to dist/taga11y.cjs,
// so require('taga11y') resolves to the CJS bundle automatically.
{
"exports": {
".": {
"import": "./dist/taga11y.mjs", // ESM → import Taga11y from 'taga11y'
"require": "./dist/taga11y.cjs", // CJS → require('taga11y')
"types": "./dist/taga11y.d.ts" // TypeScript
}
},
"main": "./dist/taga11y.cjs", // CJS fallback
"module": "./dist/taga11y.mjs", // ESM fallback (tree-shaking)
}