Packaging and distributable builds
Less.js uses one pnpm workspace to deliver the Less compiler to Node.js, the lessc command, and browsers. The workspace keeps the product package separate from test support packages, then maps shared compiler behavior to artifacts for each consumer's module format.
Workspace package boundaries
The workspace is the unit for local development and version alignment. It contains a private root project, the published less compiler package, a published fixture package, and a private package that lets tests check imports from node_modules.
Package roles
Each package has a separate delivery role. The root project coordinates scripts and tools. The less package is the product package. The two test packages support compiler tests without becoming part of the product package.
| Package | Role | Publication status |
|---|---|---|
@less/root | Workspace scripts and development tools | Private |
less | Compiler API, lessc, source modules, and built bundles | Published |
@less/test-data | Less inputs and expected CSS for compiler tests | Published |
@less/test-import-module | Test files used to check package import resolution | Private |
The workspace includes each directory under packages/*. The less package links the test packages as workspace development dependencies. This keeps test assets outside the product package while preserving local package resolution.
References: pnpm-workspace.yaml• L1-2 package.json• L1-18 packages/…/package.json• L79-81 packages/…/package.json• L1-18 packages/…/package.json• L1-11
Compiler entry points
The package has one compiler core and runtime entry points for Node.js and browsers. Each runtime entry point supplies the services that its environment needs while keeping Less language behavior shared.
Shared compiler core
The shared entry point creates the public compiler API from an environment, file managers, and a version. Runtime adapters use this boundary instead of defining separate compiler behavior for each target.
References: packages/…/index.js• L1-23 packages/…/index.js• L32-58 packages/…/index.js• L61-94
Node.js and command-line entry points
The Node entry point combines the shared core with services for local files, URLs, plugins, and other Node resources. The lessc command uses that API to read Less input and write CSS or source-map output. These entry points serve server-side code and command-line compilation; see Node API and lessc.
The package maps JavaScript consumers to two Node forms. An ES module import uses the source module under lib. A CommonJS consumer uses the built dist/less-node.cjs bundle. The index.cjs bridge also loads that CommonJS bundle for direct CommonJS use.
References: packages/…/index.js• L1-30 packages/…/lessc• L1-11 packages/…/lessc• L76-91 packages/…/lessc• L308-324 packages/…/package.json• L25-41 packages/…/index.cjs• L1-2
Browser entry point
The browser entry point starts the browser adapter, reads page-level Less options, registers browser stylesheets, and exposes the API as window.less. The build turns it into a script that runs without a Node module loader. The browser runtime after bundle load is described in Browser runtime.
References: packages/…/bootstrap.js• L1-30 packages/…/bootstrap.js• L32-67
Rollup browser and Node builds
The Rollup build turns runtime entry points into files for package consumers. A distribution build writes a Node CommonJS bundle and browser bundles. A local build writes equivalent files under tmp so tests and local checks do not replace release artifacts.
Build targets
The build uses dist when called with --dist and uses tmp otherwise. It bundles the Node entry point as less-node.cjs. It bundles the browser bootstrap as UMD so a browser script can expose the global less value.
| Target | Entry point | Output purpose |
|---|---|---|
| Node | lib/…/index.js | CommonJS bundle for require('less') |
| Browser | lib/…/bootstrap.js | UMD browser bundle for script loading |
| Browser minimized | Same browser entry point | Smaller UMD bundle for production pages |
The browser build can write one requested output with --out. Without that option it writes the normal browser files and the browser CommonJS-named compatibility file. The package build uses node build/rollup.js --dist. Test tasks use temporary browser output so test artifacts do not act as release artifacts.
References: packages/…/package.json• L58-68 packages/…/rollup.js• L17-20 packages/…/rollup.js• L58-76 packages/…/rollup.js• L79-143 packages/…/Gruntfile.cjs• L185-205
Bundle compatibility
The build includes the modules needed by each target and adapts Node-only module behavior for the Node bundle. This gives CommonJS users a stable built file while modern Node users retain an ES module path. Browser output uses browser services and publishes a global named less.
References: packages/…/rollup.js• L21-56 packages/…/rollup.js• L61-76 packages/…/rollup.js• L92-119 packages/…/package.json• L29-41
Generated banners and version identity
Each distributable bundle receives a license banner made from less package metadata. The banner identifies the product, version, author, and license in the artifact itself.
The Node bundle also embeds the package version during bundling. This keeps the reported compiler version aligned with the package that produced the bundle, even when the bundle runs outside the source package directory. The minifier keeps the license comment in the minimized browser file.
References: packages/…/banner.js• L1-16 packages/…/rollup.js• L38-55 packages/…/rollup.js• L71-76 packages/…/rollup.js• L96-106 packages/…/rollup.js• L133-142
Published artifact formats
The published less package provides source modules for supported imports and built files for compatibility paths. Its export map selects an artifact from the consumer's module kind and environment.
Consumer format mapping
The package supports Node imports, command-line use, browser package loading, and browser script loading. The export conditions choose the matching artifact rather than requiring consumers to infer a file path.
| Consumer or use | Package path | Format |
|---|---|---|
| Node ES module import | lib/…/index.js | ES module |
| Node CommonJS import | dist/less-node.cjs | CommonJS bundle |
| Browser package condition | dist/less.cjs | Browser bundle selected by exports |
| Browser script or legacy browser field | dist/less.js | UMD browser bundle |
| Minimized browser script | dist/less.min.js | Minimized UMD bundle with source map |
| Command line | bin/lessc | Node executable |
The npm package includes bin, lib, dist, index.cjs, and README.md. It excludes source maps under lib but keeps the browser minified bundle's generated map. Test-only workspace packages are not included inside less.
References: packages/…/package.json• L26-54 packages/…/package.json• L46-52 packages/…/rollup.js• L121-142
Build and publication handoff
Build output is part of the publication contract. Before the less package is published, its type check, distribution build, and Node test set run through prepublishOnly. This keeps the package registry artifact tied to a checked build.
Stable and beta release paths publish named non-private workspace packages. They synchronize package versions before publication. The package metadata used for banners and embedded version data must therefore match the version sent to the registry; release policy belongs in Release automation.
References: packages/…/package.json• L67-68 scripts/bump-and-publish.js• L127-161 scripts/bump-and-publish.js• L228-239 scripts/publish-beta.js• L42-60 scripts/publish-beta.js• L81-114
Change checklist
When these files or sections are changed, remember to consider these:
- Keep packages/…/package.json export paths, the
filesallow-list, and Rollup output names aligned. A valid build can still produce an unusable npm package when one contract diverges. - Keep the shared compiler API and both runtime adapters compatible with their module conditions. A core change can affect the Node source path and both browser bundles.
- Treat package version metadata as build input. Changes to version handling can make the package version, embedded Node version, and generated banner disagree.
- Preserve the
tmpversusdistsplit when changing test or release build commands. Test output must not replace files intended for publication. - Keep package privacy and publication settings aligned with release selection. A change to a test package manifest can change which workspace packages reach the registry.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
An export points to a file that Rollup does not write or the npm files list omits | A consumer receives a package with a broken import or missing browser script | Keep exports, browser, main, and the files list synchronized with build outputs |
| A distribution build uses stale package metadata | The compiler reports or displays a version that does not match the published package | Build after version synchronization and use the generated banner and embedded version from the same package metadata |
| The browser bundle is built from the Node entry point | Browser loading can require Node services that are not available on a page | Use the browser bootstrap as the browser Rollup entry point |
| A release publishes before distribution files are rebuilt | CommonJS or browser consumers receive stale artifacts | Keep the prepublishOnly build and Node checks in the publication path |
| A package privacy or publish setting changes without the release selector changing with it | Test support files can be published unexpectedly or a needed package can be skipped | Check package names and privacy or publish settings against the stable and beta package selection |
Key files
| File | Why to read it |
|---|---|
| pnpm-workspace.yaml | Defines the workspace package boundary. |
| package.json | Defines root ownership, package-manager use, and workspace-level build and release commands. |
| packages/…/package.json | Defines package exports, included files, runtime entry points, and build hooks. |
| packages/…/package.json | Shows the published test-data package boundary. |
| packages/…/package.json | Shows the private package boundary used for import tests. |
| packages/…/index.js | Shows the shared compiler API boundary used by runtime adapters. |
| packages/…/index.js | Shows the Node compiler entry point that feeds the Node bundle and lessc. |
| packages/…/bootstrap.js | Shows the browser entry point used to create the browser bundle. |
| packages/…/rollup.js | Defines Node and browser bundle targets and output formats. |
| packages/…/banner.js | Defines the metadata banner placed in distributable bundles. |
packages/less/bin/lessc | Defines the command-line entry point that uses the Node API. |
| scripts/bump-and-publish.js | Shows which workspace packages are publishable and how stable publication consumes package versions. |
| scripts/publish-beta.js | Shows the local beta build and publication handoff. |