Skip to content

Commit 9680de8

Browse files
refactor: convert source to ESM with dual ESM/CJS build (#593)
1 parent a2e2074 commit 9680de8

16 files changed

Lines changed: 133 additions & 1164 deletions

.changeset/convert-to-esm.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"less-loader": major
3+
---
4+
5+
The package now ships native ESM as well as CommonJS. `"type": "module"` is set, and an `exports` map exposes `dist/esm/index.js` to `import` and `dist/cjs/index.js` to `require`. Less is loaded via dynamic `import()` instead of `require()`.

.cspell.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
"iscolor",
1111
"klona",
1212
"FOUC",
13-
"sourcemaps",
14-
"commitlint"
13+
"sourcemaps"
1514
],
1615

1716
"ignorePaths": [

.github/workflows/nodejs.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ jobs:
5252
- name: Security audit
5353
run: npm run security
5454

55-
- name: Validate PR commits with commitlint
56-
if: github.event_name == 'pull_request'
57-
run: npx commitlint --from ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }} --to ${{ github.event.pull_request.head.sha }} --verbose
58-
5955
test:
6056
name: Test - ${{ matrix.os }} - Node v${{ matrix.node-version }}, Webpack ${{ matrix.webpack-version }}
6157

.husky/commit-msg

Lines changed: 0 additions & 1 deletion
This file was deleted.

babel.config.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
const MIN_BABEL_VERSION = 7;
22

3-
module.exports = (api) => {
3+
export default (api) => {
44
api.assertVersion(MIN_BABEL_VERSION);
5-
api.cache(true);
5+
6+
const env = api.env();
7+
const isEsm = env === "esm";
68

79
return {
810
presets: [
@@ -12,6 +14,8 @@ module.exports = (api) => {
1214
targets: {
1315
node: "22.11.0",
1416
},
17+
modules: isEsm ? false : "commonjs",
18+
exclude: ["transform-dynamic-import"],
1519
},
1620
],
1721
],

commitlint.config.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

eslint.config.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
99
export default defineConfig([
1010
{
1111
extends: [configs["recommended-dirty"]],
12+
languageOptions: {
13+
ecmaVersion: 2025,
14+
},
1215
},
1316
{
1417
files: ["test/**/*.{js,cjs,mjs}"],

lint-staged.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = {
1+
export default {
22
"*": [
33
"prettier --cache --write --ignore-unknown",
44
"cspell --cache --no-must-find-files",

0 commit comments

Comments
 (0)