diff --git a/.github/workflows/usage.yml b/.github/workflows/usage.yml index 5608b2eba..17ea41c11 100644 --- a/.github/workflows/usage.yml +++ b/.github/workflows/usage.yml @@ -64,9 +64,11 @@ jobs: export UNPACK_DESTINATION=$(mktemp -d) mv mustache.tgz $UNPACK_DESTINATION cp test/module-systems/esm-test.mjs $UNPACK_DESTINATION + cp test/module-systems/esm-test-exports.mjs $UNPACK_DESTINATION cd $UNPACK_DESTINATION npm install mustache.tgz node esm-test.mjs + node esm-test-exports.mjs browser-usage: runs-on: ubuntu-latest diff --git a/package.json b/package.json index e938a83b2..cf9887cd3 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,13 @@ "mustache.min.js", "wrappers/" ], + "exports": { + ".": { + "import": "./mustache.mjs", + "require": "./mustache.js" + }, + "./*": "./*" + }, "volo": { "url": "https://raw.github.com/janl/mustache.js/{version}/mustache.js" }, diff --git a/test/module-systems/esm-test-exports.mjs b/test/module-systems/esm-test-exports.mjs new file mode 100644 index 000000000..d79feb629 --- /dev/null +++ b/test/module-systems/esm-test-exports.mjs @@ -0,0 +1,12 @@ +import assert from 'assert'; +import mustache from 'mustache'; + +const view = { + title: 'Joe', + calc: () => 2 + 4 +}; + +assert.strictEqual( + mustache.render('{{title}} spends {{calc}}', view), + 'Joe spends 6' +);