Skip to content

Commit ea3adcf

Browse files
authored
Add package.json exports field (#773)
These changes adds an `exports` field to package.json with the main goal of allowing the root/main export to be our ESM syntax version of the package, as opposed to the UMD/CommonJS version. This will make it easier for using projects written with ESM to use mustache.js out of the box, without having to figure out that they'd have to `import mustache/mustache.mjs` to get the ESM version. It is also assumed to be beneficial for tools like http://skypack.dev to choose the correct ESM version when appropriate. Refs https://nodejs.org/api/packages.html#packages_package_entry_points
1 parent f15befd commit ea3adcf

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

.github/workflows/usage.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,11 @@ jobs:
9090
export UNPACK_DESTINATION=$(mktemp -d)
9191
mv mustache.tgz $UNPACK_DESTINATION
9292
cp test/module-systems/esm-test.mjs $UNPACK_DESTINATION
93+
cp test/module-systems/esm-test-exports.mjs $UNPACK_DESTINATION
9394
cd $UNPACK_DESTINATION
9495
npm install mustache.tgz
9596
node esm-test.mjs
97+
node esm-test-exports.mjs
9698
9799
browser-usage:
98100
runs-on: ubuntu-latest

package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@
2424
"mustache.min.js",
2525
"wrappers/"
2626
],
27+
"exports": {
28+
".": {
29+
"import": "./mustache.mjs",
30+
"require": "./mustache.js"
31+
},
32+
"./*": "./*"
33+
},
2734
"volo": {
2835
"url": "https://raw.github.com/janl/mustache.js/{version}/mustache.js"
2936
},
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import assert from 'assert';
2+
import mustache from 'mustache';
3+
4+
const view = {
5+
title: 'Joe',
6+
calc: () => 2 + 4
7+
};
8+
9+
assert.strictEqual(
10+
mustache.render('{{title}} spends {{calc}}', view),
11+
'Joe spends 6'
12+
);

0 commit comments

Comments
 (0)